Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 romping around the Monastery: (12)
As of 2014-09-19 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (144 votes), past polls