Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Uploading a File

by sredhar8 (Novice)
on Feb 06, 2003 at 09:26 UTC ( #233087=perlquestion: print w/replies, xml ) Need Help??

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

I have written the code for CGI from for uploading a file and saving it in the current directory but its not working (no error messages but wont do anything) ..any help??
print start_multipart_form(),"Enter File :: ",filefield('filename','', +50),br,,submit('submit','Upload'),endform; if(my $file= param('filename')) { my $tmpFile = tmpFileName($file); } open (WQ,">>outdata.txt"); while(<$file>) { print WQ; } close(WQ);

Thank you...
Newbiemonk

20030206 Edit by Corion : Added code tags

Replies are listed 'Best First'.
Re: Uploading a File
by tachyon (Chancellor) on Feb 06, 2003 at 10:44 UTC

    Either do a Super Search for file upload problem or Read The Friendly Manual in the form of the CGI::Simple documentation (better than the CGI docs although the interface is the same). In the docs I have explained it in minute detail, please take the time to read them, do it as shown, and it will work.

    You probably want this, which is nothing like your code. You need to read from the temporary upload file handle and write it to you output file. If there is no 'filename' param we show the upload html. >file means overwite (make new file if does not exist) >>file means append to the file BTW:

    #!/usr/bin/perl use CGI ':standard'; if ( param('filename') ) { my $input_filehandle = upload( 'filename' ); open WQ, ">outdata.txt" or die_nice("Can't open outdata.txt, Perl +says $!"); print WQ $_ while <$input_filehandle>; close WQ; print header(), "Uploaded OK"; } else { print header(), start_multipart_form(), "Enter File :", filefield('filename','',50), br, submit('submit','Upload'), endform; } sub die_nice { print header(), shift }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Uploading a File
by kodo (Hermit) on Feb 07, 2003 at 08:25 UTC
    Hello,

    I'd suggest you to have a look at CGI::Upload from rob_au.
    It takes care of a lot of problems you could encounter when trying to code an upload-script and will prolly save you some time....

    kodo

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2022-12-02 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?