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

In reply to file upload and IO::Handle by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.