Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

by Anonymous Monk
on Mar 11, 2002 at 00:36 UTC ( #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 => ''; use SERVER => ''; 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' => '' }); 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&&[@.]/&&s&.com.&_&&&print'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://150786]
[Tanktalus]: What's so happy about it? :P
[Tanktalus]: ww: your parens don't line up. Sure, perl can look like line noise, but the parens still have to line up. ;)
[Tux]: 1nickt did you build 5.24.3, 5.26.1, and 5.27.4 yet?
Tux now has 284 working versions of perl
[1nickt]: Tux oh yes, have filed reports from them already :-)
1nickt has 44 for one version of one OS ...
[Tux]: good boy :)
[1nickt]: Had to beat on things for a bit to get cpanminus working on 5.8.9, and it just would not go on 5.6.2, so I abndoned that one for cpanm-reporter work. I mean realistically how many people are using 5.6.2 on OS X ? :-/
[Tux]: those 284 are all on my laptop (Linux x64)
[Tanktalus]: Hmm, I only have 26 on my machine... :P

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2017-09-25 16:36 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (282 votes). Check out past polls.