Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: CGI::Upload - CGI class for handling browser file uploads

by Anonymous Monk
on Mar 11, 2002 at 00:36 UTC ( [id://150786]=note: print w/replies, xml ) Need Help??


in reply to CGI::Upload - CGI class for handling browser file uploads

Hi, would someone please be kind and post an example cgi script that uses this nice module for uploading?
  • Comment on Re: CGI::Upload - CGI class for handling browser file uploads

Replies are listed 'Best First'.
Re: Re: CGI::Upload - CGI class for handling browser file uploads
by rob_au (Abbot) on Mar 11, 2002 at 03:27 UTC
    The following is a quick modification of an older script which I've now rewritten to use the CGI::Upload module - This little script will accept uploaded files of a specified mime type, in this example image/gif, and send them through to the email address specified.

    #!/usr/bin/perl -Tw use EMAIL => 'user@yourdomain.com'; use SERVER => 'mail.yourdomain.com'; use CGI; use CGI::Upload; use Mail::Mailer; use Net::SMTP; use strict; my $cgi = CGI->new; my $upload = CGI::Upload->new( $cgi ); if ( $upload->mime_type('upload') eq 'image/gif' ) { my $mail = Mail::Mailer->new( 'smtp', Server => SERVER ); $mail->open({ 'To' => EMAIL, 'From' => 'root@yourdomain.com' }); my $buffer; my @results; my $fh = $upload->file_handle('upload'); while (read($fh, $buffer, 45)) { push (@results, pack("u", $buffer)); } $fh->close; print $mail join "", "begin 600 " . $upload->file_name('upload') . "\n", @results, "end\n\n"; $mail->close; } print STDOUT $cgi->redirect( $ENV{'HTTP_REFERER'} ); exit 0;

     

    perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2024-04-23 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found