The script below uploads the selected file and creates it on the
server in the right directory and all looks fine. But the file is
empty, it contains nothing...
HTML FORM:
<form name="foo" method="post" action="../upload_image.pl "
target="_self" enctype="multip art/form-data">
<input type="file" name="file"><in put type="text"
name="filename" ></form>
Perl script:
#!/usr/bin/perl
use CGI;
use Cwd;
#print "Content-type: text/html \n\n";
#Setup query from cgi
my $cgi = new CGI;
#Setup upload directory
$uploaddir = "/client_image_up loaddir";
$file = $cgi -> param("file");
$file =~ s/.*[\/\\](.*)/$1/;
$filename = $cgi -> param("filename ");
$datestr = time;
#Handle the upload
open FHUP, ">$uploaddi r/$file" or die;
binmode FHUP;
undef $Buffer;
while( read( $file, $Buffer, 1024 ) ){
print FHUP $Buffer;
}
close (FHUP);
print $cgi -> header();
print "<h3>Filen '$filename' blev uploaded!</h3>";
print "<img src=client_imag e_uploaddir/$file alt=$filename> ";
print "<a href=\"javascri pt:void(history .back());\">Til bage</a> <a
href=\"javascri pt:void(window. close());\">Luk vindue</a>";
I also tried without 'buffering' and the result is the same, file is
created but with no content.
Any ideas?
/Kristian
server in the right directory and all looks fine. But the file is
empty, it contains nothing...
HTML FORM:
<form name="foo" method="post" action="../upload_image.pl "
target="_self" enctype="multip art/form-data">
<input type="file" name="file"><in put type="text"
name="filename" ></form>
Perl script:
#!/usr/bin/perl
use CGI;
use Cwd;
#print "Content-type: text/html \n\n";
#Setup query from cgi
my $cgi = new CGI;
#Setup upload directory
$uploaddir = "/client_image_up loaddir";
$file = $cgi -> param("file");
$file =~ s/.*[\/\\](.*)/$1/;
$filename = $cgi -> param("filename ");
$datestr = time;
#Handle the upload
open FHUP, ">$uploaddi r/$file" or die;
binmode FHUP;
undef $Buffer;
while( read( $file, $Buffer, 1024 ) ){
print FHUP $Buffer;
}
close (FHUP);
print $cgi -> header();
print "<h3>Filen '$filename' blev uploaded!</h3>";
print "<img src=client_imag e_uploaddir/$file alt=$filename> ";
print "<a href=\"javascri pt:void(history .back());\">Til bage</a> <a
href=\"javascri pt:void(window. close());\">Luk vindue</a>";
I also tried without 'buffering' and the result is the same, file is
created but with no content.
Any ideas?
/Kristian
Comment