Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

I need a script for web file uploading.

by Anonymous Monk
on Jun 13, 2000 at 20:17 UTC ( [id://17909]=perlquestion: print w/replies, xml ) Need Help??

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

I need a script for web file uploading.

Originally posted as a Categorized Question.

  • Comment on I need a script for web file uploading.

Replies are listed 'Best First'.
Re: I need a script for web file uploading.
by cLive ;-) (Prior) on Nov 15, 2001 at 06:18 UTC

    Here's a simple example script.

    #!/usr/bin/perl -w use strict; # make html/forms easy to deal with use CGI; # report errors in the browser # (remove from production code) use CGI::Carp 'fatalsToBrowser'; # create new CGI object my $q = new CGI; if ( ! $q->param() ) { # first run, so present form print $q->header, $q->start_html, $q->start_multipart_form, $q->filefield('file'), $q->br, $q->submit('Upload'), $q->end_form, $q->end_html; } else { # file uploaded, so process it # read filehandle from param and set to binary mode my $filehandle = $q->param('file'); binmode $filehandle; # open file for output. Change this to suit your needs!!! open OUT, "> /path/to/local/filename" or die $!; binmode OUT; # process $filehandle { my $buffer; while ( read $filehandle, $buffer, 1024 ) { print OUT $buffer; } } close OUT; # show success print $q->header, $q->start_html, $q->p('File uploaded'), $q->end_html; }

Re: How can I get started with a file upload script?
by Anonymous Monk on Jun 28, 2000 at 23:43 UTC
    Here's one:
    $SIG{__DIE__} = \&my_die; use CGI; $C = new CGI; if ($C->param) { $file=$C->param("upload"); ### if you need to do fancy placement look at ### File::Basename open (UPLOAD, "/path/to/file"); while ($bytesread=read($file,$buffer,1024)) { print UPLOAD $buffer; } print $C->header; print $C->start_html; print qq(<p>file uploaded successfully</p>); print $C->end_html; exit; } else { print $C->header; print $C->start_html; print $C->start_multipart_form; print $C->filefield(-name=>'file'); print qq(<input type="submit" name="submit" value="submit"> </form> ); print $C->end_html; exit; } sub my_die { print $C->header; print $C->start_html; print $_; print $C->end_html; }

    Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-04-19 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found