picture upload script problems. PLEASE HELP!

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::pOST_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
 
W

wfsp

eddav said:
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:
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

You were given a full and detailed answer here:

http://www.perlmonks.org/index.pl?node_id=392083
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top