Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
and here's the HTML 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 10000 +k 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 fileha +ndle 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 d +esired. print "</body>"; print "</html>";
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! From Edwin<FORM ACTION="http://192.168.1.50/cgi-bin/upload2.pl" METHOD="post" EN +CTYPE="multipart/form-data"> Photo to Upload: <INPUT TYPE="file" NAME="pic"> <br><br> <INPUT TYPE="submit" NAME="Submit" VALUE="Submit Form"> </FORM>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Picture upload script!
by jZed (Prior) on Sep 19, 2004 at 03:44 UTC | |
|
Re: Picture upload script!
by kesterkester (Hermit) on Sep 19, 2004 at 02:10 UTC | |
|
Re: Picture upload script!
by Errto (Vicar) on Sep 19, 2004 at 03:51 UTC | |
|
Re: Picture upload script!
by TedPride (Priest) on Sep 19, 2004 at 05:20 UTC |