I'm stumped. I have a script that uploads a file to the server with an associated description on a linux system running Apache and Perl 5.6. This script works on other similar systems, but not on this one. The form looks like this:

<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!


In reply to file from multipart form not being written to the server! by AztecMonkey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.