K
Kristian
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="multipart/form-data">
<input type="file" name="file"><input 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_uploaddir";
$file = $cgi -> param("file");
$file =~ s/.*[\/\\](.*)/$1/;
$filename = $cgi -> param("filename");
$datestr = time;
#Handle the upload
open FHUP, ">$uploaddir/$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_image_uploaddir/$file alt=$filename> ";
print "<a href=\"javascript:void(history.back());\">Tilbage</a> <a
href=\"javascript: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="multipart/form-data">
<input type="file" name="file"><input 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_uploaddir";
$file = $cgi -> param("file");
$file =~ s/.*[\/\\](.*)/$1/;
$filename = $cgi -> param("filename");
$datestr = time;
#Handle the upload
open FHUP, ">$uploaddir/$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_image_uploaddir/$file alt=$filename> ";
print "<a href=\"javascript:void(history.back());\">Tilbage</a> <a
href=\"javascript: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