E
eddav
Hello,
I have found a perl script on the internet I wish to use for uploading
files to a site, but I have been unsuccessfull in using it. I am very
new to perl, so am not sure what's wrong with the code.
Here's the perl code:
#!/usr/bin/perl -wT
#use CGI;
use CGI qw(warningsToBrowser fatalsToBrowser);
#use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
$CGI:OST_MAX = 10000000; # Added as an example - limit POST to
10000k
my $q = new CGI; # Create new query object
my $filename = $q->param("pic");
my $upload_filehandle = $q->upload("pic"); # Corrected
my $upload_dir="/pics";
$filename =~ s/.*[\/\\](.*)/$1/;
print $q->header ("text/html" );
open UPLOADFILE, ">$upload_dir/$filename";
binmode UPLOADFILE; # to specify binary file operations on this
filehandle
my $total_bytes = 0;
while (my $bytes_read = read($upload_filehandle, $buffer, 1024)) {
print UPLOADFILE $buffer;
$total_bytes += $bytes_read;
}
close $upload_filehandle;
close UPLOADFILE;
print "<html>";
print "<head>";
print "<title>Thanks..!!!</title></head>"; # note closing head tag
print "<body>";
print "<P>Thanks for uploading your photo!</P>";
print "<P>Your photo:</P>";
print "<img src=\"/pics/$filename\" border=\"0\">";
print "<p>Size of photo is $total_bytes bytes.</p>"; # Added line if
desired.
print "</body>";
print "</html>";
and here's the HTML code:
<FORM ACTION="http://192.168.1.50/cgi-bin/upload2.pl" METHOD="post"
ENCTYPE="multipart/form-data">
Photo to Upload: <INPUT TYPE="file" NAME="pic">
<br><br>
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit Form">
</FORM>
The html page works ok, put the picture isn't actually uploaded, so it
just shows a broken picture icon. The apache error_log states:
print() on closed filehandle main::UPLOADFILE at
/Library/WebServer/CGI-Executables/upload2.pl line 23.
and also that the .jpg file doesn't exist.
I am testing it on my mac (OS 10.2) but but hope to put it up on my
site at nic.nac.wdyn.de. Any help is much appreciated!
Edwin
I have found a perl script on the internet I wish to use for uploading
files to a site, but I have been unsuccessfull in using it. I am very
new to perl, so am not sure what's wrong with the code.
Here's the perl code:
#!/usr/bin/perl -wT
#use CGI;
use CGI qw(warningsToBrowser fatalsToBrowser);
#use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
$CGI:OST_MAX = 10000000; # Added as an example - limit POST to
10000k
my $q = new CGI; # Create new query object
my $filename = $q->param("pic");
my $upload_filehandle = $q->upload("pic"); # Corrected
my $upload_dir="/pics";
$filename =~ s/.*[\/\\](.*)/$1/;
print $q->header ("text/html" );
open UPLOADFILE, ">$upload_dir/$filename";
binmode UPLOADFILE; # to specify binary file operations on this
filehandle
my $total_bytes = 0;
while (my $bytes_read = read($upload_filehandle, $buffer, 1024)) {
print UPLOADFILE $buffer;
$total_bytes += $bytes_read;
}
close $upload_filehandle;
close UPLOADFILE;
print "<html>";
print "<head>";
print "<title>Thanks..!!!</title></head>"; # note closing head tag
print "<body>";
print "<P>Thanks for uploading your photo!</P>";
print "<P>Your photo:</P>";
print "<img src=\"/pics/$filename\" border=\"0\">";
print "<p>Size of photo is $total_bytes bytes.</p>"; # Added line if
desired.
print "</body>";
print "</html>";
and here's the HTML code:
<FORM ACTION="http://192.168.1.50/cgi-bin/upload2.pl" METHOD="post"
ENCTYPE="multipart/form-data">
Photo to Upload: <INPUT TYPE="file" NAME="pic">
<br><br>
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit Form">
</FORM>
The html page works ok, put the picture isn't actually uploaded, so it
just shows a broken picture icon. The apache error_log states:
print() on closed filehandle main::UPLOADFILE at
/Library/WebServer/CGI-Executables/upload2.pl line 23.
and also that the .jpg file doesn't exist.
I am testing it on my mac (OS 10.2) but but hope to put it up on my
site at nic.nac.wdyn.de. Any help is much appreciated!
Edwin