Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Getting a filehandle for uploaded file

by bv (Friar)
on Oct 20, 2009 at 15:15 UTC ( #802250=note: print w/replies, xml ) Need Help??

in reply to Getting a filehandle for uploaded file

Is the problem that you are trying to read from the filename, not the filehandle? From the CGI documentation:

To be safe, use the upload() function (new in version 2.47). When called with the name of an upload field, upload() returns a filehandle-like object, or undef if the parameter is not a valid filehandle.

Pulling a quote from Bloodnok's post below:

If there was a problem uploading the file -- for example, the file was bigger than the $CGI::POST_MAX setting -- $filename will be empty. We can test for this and report the problem to the user as follows:

So you could test for that, too.

print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))

Replies are listed 'Best First'.
Re^2: Getting a filehandle for uploaded file
by luker (Initiate) on Oct 20, 2009 at 15:51 UTC
    I've tried using the upload function. It returns undef, which, according to the man page, means the parameter is not a valid filehandle. But why not? I have a normal looking form field:
    <input type="file" name="file_image" ...
    I've done the test according to your second quote. There's definitely nothing coming back from:
    my $handle_in = $cgi->upload('file_image');
    But it's not a POST_MAX problem. That's set to -1, which means no limit. There's a function called cgi_error(), but that's not returning anything either.

      Did you specify the correct enctype for your form?

      <form enctype="multipart/form-data" method="POST" ...>

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://802250]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2020-02-22 07:24 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (98 votes). Check out past polls.