Please please please someone put me out of my misery! There must be something (extremely!) simple I am forgetting/doing wrong as I have tried this on several setups and I get the same result. Here is my HTML:
<!DOCTYPE HTML><html><body> Or upload a new file<br><br> <form id = 'email-upload-form' name='email-upload-form' action='/cgi-b +in/testform/upload.pl' method='POST'> <input type = 'file' name='emailupload' enctype="multipart/form-data"/ +><button name='submit-button' id='upload-button' type='submit'>upload +</button> </form> </body> </html>
and my perl script to pick up the file:
#!/usr/bin/perl use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); my $query = new CGI(); print "Content-type: text/html\n\n"; my @params = $query->param; print "params are @params<br>\n"; my $fh = $query->upload('emailupload'); print "fh contains $fh and is a ".ref(\$fh)."<br>\n"; print "fh is not defined!" if(!defined($fh)); print "$_\n" while(<$fh>);
The output of which, when I try to upload a dummy text file is
params are emailupload submit-button fh contains and is a SCALAR fh is not defined!

In fact it does exactly the same thing if I hit 'upload' without first selecting a file.

BTW I read that doing operations on $fh other than file handle operations results in it losing its 'magic' and becoming a scalar - however even if I have

#!/usr/bin/perl use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); my $query = new CGI(); print "Content-type: text/html\n\n"; my $fh = $query->upload('emailupload'); print "$_\n" while(<$fh>);
I still get no output... I know I'm going to kick myself when I finally find out but.. can anyone identify what excruciating silly thing I am (not) doing?

In reply to such a simple question about file uploads... but its killing me!! by tomgracey

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.