With the code shown, not sure what's wrong. I've just taken your example and, with a few tweaks, the following runs fine on my box:

<FORM ACTION="path_to_form.cgi" METHOD="POST" ENCTYPE="multipart/form- +data"> <INPUT TYPE="text" NAME="filename" SIZE="10" MAXLENGTH="50"> <INPUT TYPE="FILE" NAME="upfile"> <INPUT TYPE="submit" VALUE="upload"> </FORM> #!/usr/bin/perl -w use strict; use warnings; use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser'; $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = 52428800; my $SAVE_DIRECTORY = "/tmp"; my $query=new CGI; my $filename = $query->param("filename") or die "no filename"; # you need to check that the filename only contains sane characters # otherwise you could have users writing anywhere in the file system die "bad filename" unless $filename =~ m/^\w+$/; my $fh = $query->upload("upfile") or die "no file"; # you realise this could allow multiple users to write to the same # filename at the same time. probably not what you want. open(OUTFILE, ">$SAVE_DIRECTORY\/$filename") or die "open failed ($!)" +; binmode OUTFILE; my ($bytes, $buffer, $size); while ($bytes = read($fh,$buffer,1024)) { $size+=$bytes; print OUTFILE $buffer; }; # read can fail with undef - you need to check :-) die "read failure ($!)" unless defined($bytes); close(OUTFILE); print $query->header; print "$filename uploaded: $size bytes" if $size > 0;

Try the above on your machine and see if it works

Personally, I would suspect your HTML - it looks like you're not passing upfile for some reason...

The best way of solving this sort of problem is to actually write a smaller version of the code that demonstrates the problem. Once you have your "other code" and "other html" out of the way the error will probably become obvious :-)


In reply to Re^3: Yet another CGI Upload problem - not like the others! by adrianh
in thread 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.