Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

CGI.pm - uploadInfo() - Simply not working

by wigwam (Initiate)
on Oct 24, 2006 at 15:24 UTC ( [id://580299]=perlquestion: print w/replies, xml ) Need Help??

wigwam has asked for the wisdom of the Perl Monks concerning the following question:

Hi! I've got
sub fileUpload { my $q = new CGI; if( my $id = $q->param( 'id' ) ) { #....... } elsif ( my $fileName = $q->upload( 'uploadfile' ) ) { my $fileInfo = $q->uploadInfo($fileName); print "Content-Type: text/html\n\n"; print "uploadInfo:<br>"; print "###$fileName###"; print $q->uploadInfo($fileName)->{'Content-Type'}; #map {print " $_: " . $fileInfo->{$_} . "<br>\n" } sort keys +%$fileInfo; exit(0); #.....
I get "Can't use an undefined value as a HASH reference". I Searched the whole net, but found no solution for this... Thanks! wigwam

Replies are listed 'Best First'.
Re: CGI.pm - uploadInfo() - Simply not working
by gellyfish (Monsignor) on Oct 24, 2006 at 15:44 UTC

    Just a guess but did you put

    enctype="multipart/form-data"
    in your form element?

    /J\

Re: CGI.pm - uploadInfo() - Simply not working
by davorg (Chancellor) on Oct 24, 2006 at 15:41 UTC

    Sounds like $q->uploadInfo($fileName) is returning "undef" rather than the expected hash reference. Given that you've already extracted that value into $fileInfo a few lines earlier, it might make sense to check that you've got what you hope you've got (i.e. a hash reference) before going ahead and trying to dereference it. I've always thought that the example in the CGI.pm docs that calls uploadInfo and just assumes that it works seemed a bit reckless, so I've always done that in two stages.

    All of which leaves you having to work out why you're getting "undef" rather than a useful value. Without seeing more of your code it's hard to be much help, but one idea springs to mind. It looks a bit unusual creating a CGI object in your fileUpload subroutine. Usually, you'd do that at the start at the CGI program and just pass that object around. Are you also creating a CGI object elsewhere in your program? You can only create one CGI object from each HTTP request. If you try to create a second one then all of its attributes will be undefined. Is that what has happened here?

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://580299]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-19 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found