Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
That is in the documentation for CGI...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.
not with $q so I changed the code to this:use CGI qw(:standard);
Then I got IO errors so I added this just above it:$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; } }
use IO::Handle;
Undefined subroutine Fh::handle
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file upload and IO::Handle
by choroba (Cardinal) on Sep 08, 2010 at 17:48 UTC | |
by Anonymous Monk on Sep 08, 2010 at 20:59 UTC | |
by Anonymous Monk on Sep 08, 2010 at 21:03 UTC | |
by choroba (Cardinal) on Sep 09, 2010 at 07:31 UTC | |
by Anonymous Monk on Sep 09, 2010 at 10:41 UTC | |
|