in reply to Uploading a File with CGI.pm
If your version of CGI.pm is not up to date then the upload() method will be broken or non existant. 2.47 rings a bell. Here is some code that I have used before that does work!
use CGI; # allow uploads $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = 1,024,000; my $q = new CGI; ..... sub upload_file { no strict 'refs'; # CGI < v2.47 use vvvvvv a symbolic reference f +or the filehandle my $fh = $q->upload('upfile') || $q->param('upfile');; my $buffer; open (OUTFILE, ">$path_to_files/$upname") or die_nice("Unable to create upload output file '$upname': $! +\n"); binmode $fh; binmode OUTFILE; my ($bytes, $read); while ($read = read ($fh, $buffer, 16384)) { print OUTFILE $buffer; $bytes += $read; } close OUTFILE; $bytes /= 1000; return "File '$upname' uploaded. $bytes Kb received successfully.<br +>\n"; }
The main point is that you can use the return value of $q->param('upfile') as a symbolic reference to get a filehandle. Indeed you have to in early version of CGI.pm, thus the or clause. Also note that although CGI.pm allows file uploads by default a wise admin may hack source so that they are denied by default so you should make sure they are enabled. You need to make sure that your submitting form uses the correct ENCTYPE (multipart/form-data) note that the CGI.pm default is "application/x-www-form-urlencoded" so you need to use start__multipart_form so you get a form like:
<FORM METHOD="POST" ACTION="http://somewhere.com/cgi-bin/script.cgi"; ENCTYPE="multipart/form-data"> <INPUT TYPE="file" NAME="upload_file" SIZE="42"> </FORM>
PS You can check your version of CGI.pm like this:
use CGI; print CGI:VERSION;
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|