tomgracey has asked for the wisdom of the Perl Monks concerning the following question:
and my perl script to pick up the file:<!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>
The output of which, when I try to upload a dummy text file is#!/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>);
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
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?#!/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>);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: such a simple question about file uploads... but its killing me!!
by tobyink (Canon) on Sep 12, 2012 at 08:25 UTC | |
by tomgracey (Scribe) on Sep 12, 2012 at 09:12 UTC | |
|
Re: such a simple question about file uploads... but its killing me!!
by Anonymous Monk on Sep 12, 2012 at 08:30 UTC | |
|
Re: such a simple question about file uploads... but its killing me!!
by Anonymous Monk on Sep 12, 2012 at 08:25 UTC |