Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

CGI file upload

by Reims (Initiate)
on Aug 01, 2013 at 11:12 UTC ( #1047433=perlquestion: print w/ replies, xml ) Need Help??
Reims has asked for the wisdom of the Perl Monks concerning the following question:

Hi! I'm trying to get a file upload script to work. To savethe uploaded file, I do this:
my $fh = $q->upload($filefield_name); #check for valid file handle if (defined $fh) { my $io = $fh->handle; open(OUTFILE, '>>', '/srv/www/cgi-bin/upload'); while ($bytesread == $io->read($buffer, 1014)) { print OUTFILE $buffer; } print "File uploaded"; } else { print "file handle not defined"; }
Executing that will give me this error:
Undefined subroutine Fh::handle at /srv/www/cgi-bin/fo_www/document_add.cgi line 51
After a couple of hours of finding loads of tutorials telling me to do exactly that, I don't know what I'm doing wrong.

Comment on CGI file upload
Select or Download Code
Re: CGI file upload
by marinersk (Chaplain) on Aug 01, 2013 at 11:36 UTC
    Interesting; I am unfamiliar withe the file handling mechanism you use; while I would love to advise you on that, I'll leave that to others.

    Here is a snippet showing how I do my file uploads:

    my $inpfsz = 0; open(RESFIL, ">$desfnm"); binmode(RESFIL); while (my $inpcnt=read($srcfnm,$inpbuf,2096)) { $inpfsz += $inpcnt; print RESFIL $inpbuf; } close(RESFIL);

    You can find more detail, including some mandatory advice about the HTML that drives the upload, at http://www.bhmk.com/mariners/cspupld.htm.

Re: CGI file upload
by Anonymous Monk on Aug 01, 2013 at 12:33 UTC
      Thanks! Using $cgi->tmpFileName does the trick for me. Greetings Reims
Re: CGI file upload
by Anonymous Monk on Aug 01, 2013 at 12:34 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-12-18 10:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (48 votes), past polls