Hello, I've been through lots of the CGI upload problem posts on this site & I can't find the solution to this enduring problem. I've been banging my head against it for ages! The problem is that I have a form for uploading a file that looks like this:
<FORM ACTION="path_to_form.cgi" METHOD="POST" ENCTYPE="multipart/form- +data"> <td><INPUT TYPE="text" NAME="filename" SIZE="10" MAXLENGTH="50"></td> <td><Other form fields....> <td><INPUT TYPE="FILE" NAME="upfile"></td> <td><Other form fields....</td> </tr> </table> <INPUT TYPE="submit" VALUE="upload"><BR> </FORM>
There are no field naming conflicts. The upload script looks like this:
#!/usr/bin/perl -w use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser'; use Fcntl qw( :DEFAULT :flock ); $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = 52428800; my $SAVE_DIRECTORY = "full_path_to_save_directory"; my $query=new CGI; my $filename=$query->param("filename") or die "$!"; my $file =$query->param("upfile") or die "$!"; my $fh =$query->upload($file) or die "$!"; <<other code>> open(OUTFILE, ">$SAVE_DIRECTORY\/$filename"); binmode OUTFILE; while ($bytes = read($fh,$buffer,1024)) { $size+=$bytes; print OUTFILE $buffer; } if ($size > 0) { print "$filename uploaded: $size bytes<p>"; }
This doesn't work though. It dies at the upload line every time. The upload directory has been chmodded to 777 and the file is created every time, if the 'die's are removed, but never populated. It seems very mysterious to me. A summary of the version of Perl I'm running reveals the following:
/usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.6.1/i386-linux /usr/lib/perl5/vendor_perl/5.6.1 /usr/lib/perl5/vendor_perl . 2.752
Can anyone see any yawning great foolish gaps in my work?

In reply to Yet another CGI Upload problem - not like the others! by stuayres

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.