Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

file upload and IO::Handle

by Anonymous Monk
on Sep 08, 2010 at 06:48 UTC ( [id://859272]=perlquestion: print w/replies, xml ) Need Help??

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

In searching for a new way to upload files, so that we can have someone who uploads videos for us, upload any files they need to, I found this:
When the form is processed, you can retrieve an IO::Handle compatibile + handle for a file upload field like this: $lightweight_fh = $q->upload('field_name'); # undef may be returned if it's not a valid file handle if (defined $lightweight_fh) { # Upgrade the handle to one compatible with IO::Handle: my $io_handle = $lightweight_fh->handle; open (OUTFILE,'>>','/usr/local/web/users/feedback'); while ($bytesread = $io_handle->read($buffer,1024)) { print OUTFILE $buffer; } } In a list context, upload() will return an array of filehandles. This +makes it possible to process forms that use the same name for multipl +e upload fields.
That is in the documentation for CGI...

What I am having a problem with is this:

I use CGI this way:
use CGI qw(:standard);
not with $q so I changed the code to this:
$lightweight_fh = upload('field_name'); # undef may be returned if it's not a valid file handle if (defined $lightweight_fh) { # Upgrade the handle to one compatible with IO::Handle: my $io_handle = $lightweight_fh->handle; open (OUTFILE,">>/home/path/to/upload_loc"); while ($bytesread = $io_handle->read($buffer,1024)) { print OUTFILE $buffer; } }
Then I got IO errors so I added this just above it:
use IO::Handle;


Now I get this error:
Undefined subroutine Fh::handle


any ideas why this is happening? I have been trying to get this to work for hours and hours now, with no success.

I appreciate any advice you can offer.

Thanks,
Rich

Replies are listed 'Best First'.
Re: file upload and IO::Handle
by choroba (Cardinal) on Sep 08, 2010 at 17:48 UTC
    What kind of thing is returned by upload(), or in other words, what is returned by ref $lightweight_fh after you assign upload to it?
      good question, how do I dump it to see?

      Thanks
      Rich
        I did die "$lightweight"; and it just prints the file name in the software error...

        So now what?

        thanks,
        Rich

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-23 06:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found