Black_Anon
Neues Mitglied
Hallo zusammen, ich hab hier einen Script und der funktioniert eigendlich gut, nur wird die ausgewählte Datei nicht gespeichert kann mir da jemand helfen?
Script:
Gruss
Black
Script:
PHP:
#!/usr/bin/perl
#
#
#
use CGI;
use strict;
my $PROGNAME = "upload/upload.pl";
my $cgi = new CGI();
print "Content-type: text/html\n\n";
#
# If we're invoked directly, display the form and get out.
#
if (! $cgi->param("button") ) {
DisplayForm();
exit;
}
#
# We're invoked from the form. Get the filename/handle.
#
my $upfile = $cgi->param('upfile');
#
# Get the basename in case we want to use it.
#
my $basename = GetBasename($upfile);
#
# At this point, do whatever we want with the file.
#
# We are going to use the scalar $upfile as a filehandle,
# but perl will complain so we turn off ref checking.
# The newer CGI::upload() function obviates the need for
# this. In new versions do $fh = $cgi->upload('upfile');
# to get a legitimate, clean filehandle.
#
no strict 'refs';
#my $fh = $cgi->upload('upfile');
#if (! $fh ) {
# print "Can't get file handle to uploaded file.";
# exit(-1);
#}
#######################################################
# Choose one of the techniques below to read the file.
# What you do with the contents is, of course, applica-
# tion specific. In these examples, we just write it to
# a temporary file.
#
# With text files coming from a Windows client, probably
# you will want to strip out the extra linefeeds.
########################################################
#
# Get a handle to some file to store the contents
#
if (! open(OUTFILE, ">tmp/outfile") ) {
print "Can't open tmp/outfile for writing - $!";
exit(-1);
}
# give some feedback to browser
print "Saving the file to tmp/outfile<br>\n";
#
# 1. If we know it's a text file, strip carriage returns
# and write it out.
#
#while (<$upfile>) {
# or
#while (<$fh>) {
# s/\r//;
# print OUTFILE "$_";
#}
#
# 2. If it's binary or we're not sure...
#
my $nBytes = 0;
my $totBytes = 0;
my $buffer = "";
# If you're on Windows, you'll need this. Otherwise, it
# has no effect.
binmode($upfile);
#binmode($fh);
while ( $nBytes = read($upfile, $buffer, 1024) ) {
#while ( $nBytes = read($fh, $buffer, 1024) ) {
print OUTFILE $buffer;
$totBytes += $nBytes;
}
close(OUTFILE);
#
# Turn ref checking back on.
#
use strict 'refs';
# more lame feedback
print "thanks for uploading $basename ($totBytes bytes)<br>\n";
##############################################
# Subroutines
##############################################
#
# GetBasename - delivers filename portion of a fullpath.
#
sub GetBasename {
my $fullname = shift;
my(@parts);
# check which way our slashes go.
if ( $fullname =~ /(\\)/ ) {
@parts = split(/\\/, $fullname);
} else {
@parts = split(/\//, $fullname);
}
return(pop(@parts));
}
#
# DisplayForm - spits out HTML to display our upload form.
#
sub DisplayForm {
print <<"HTML";
<html>
<head>
<title>Upload</title>
<link type="text/css" href="style.css" rel="stylesheet" media="screen" />
<link rel="shortcut icon" href="images/pfeil.ico">
<body>
<div id="body">
<div id="balkenoben">
<p><a href="login.php">Login<a> | <a href="register.php">Registrieren</a></p>
</div>
<div id="bild" align="center">
<image src="images/crazyhostlogo.png/">
<div id="menu">
<ul align="center">
<li><a href="index.html" >Startseite</a></li>
<li><a href="upload.html" >Upload</a></li>
<li><a href="news.html" >News</a></li>
<li><a href="produkte.html" >Produkte</a></li>
<li><a href="partner.html" >Partner</a></li>
<li><a href="kontakt.html" >Kontakt</a></li>
</ul>
</div>
</br>
<h1>Upload</h1>
<form method="post" action="$PROGNAME" enctype="multipart/form-data">
<center>
Wähle eine Datei für den Upload aus: <input type="file" name="upfile"><br>
<input type="submit" name="button" value="Upload File">
</form>
</div>
<div id="balkenunten">
</div>
</div>
HTML
}
Gruss
Black