AztecMonkey has asked for the wisdom of the Perl Monks concerning the following question:
<FORM ENCTYPE="multipart/form-data" ACTION="upload.cgi" METHOD=POST> Upload this file: <INPUT NAME="userfile" TYPE="file"><br> Description:<input type="text" name="description"><br> <INPUT TYPE="submit" VALUE="Send File"> </FORM>
The code that's processing it looks like this:
$rawfile = $cgi->param("userfile"); if ( $rawimage =~ /([\w\s\W]+)\.(\w+)/ ) { $ext = $2; } $filename = time() .".$ext"; open (OUTFILE,">./upload/$filename") or die "Could not upload file $ +filename: $!"; while ($bytesread=read($rawimage,$buffer,$ENV{'CONTENT_LENGTH'})) { print OUTFILE $buffer or die "Could not upload file $filename: $!" +; } close (OUTFILE);
And it doesn't work. It creates a zero byte file in the correct directory. I've also tried processing it like this:
use CGI qw(:all escape); use CGI::Carp qw(fatalsToBrowser); $cgi = new CGI; read($cgi->param("userfile"), $buffer, $ENV{'CONTENT_LENGTH'}); open (x,">$tempfile"); print x $buffer; close (x);
But if I take out the description field from the form, and replace $cgi->param with STDIN, it works! I've tried using $cgi->upload, to no avail.
The really bizarre thing is that if I copy the script from one account to another account with the same ISP, the original code works! I'm so baffled by this, I'm resorting to using exclamation points! Any help in figuring out why $cgi is not passing the file on would be appreciated! Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file from multipart form not being written to the server!
by antirice (Priest) on Jun 22, 2003 at 05:21 UTC | |
by AztecMonkey (Initiate) on Jun 22, 2003 at 14:02 UTC | |
|
Re: file from multipart form not being written to the server!
by gellyfish (Monsignor) on Jun 22, 2003 at 09:33 UTC | |
by AztecMonkey (Initiate) on Jun 23, 2003 at 00:31 UTC |