first of all: remember to use start_multipart_form
and not just start_form() when you generate the input form,
as in
#!/usr/bin/perl -w
use CGI qw/:standard/;
print header();
print start_html();
print start_multipart_form(-action=>'test.pl');
print filefield('file_name'), submit();
print end_form;
print end_html;
then (test.pl)
#!/usr/bin/perl -w
use strict; ## ALLWAYS!!!!
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$CGI::POST_MAX=1024 * 25;
my $q = new CGI;
my $file_name = $q->param('file_name');
my $fh = $q->upload('file_name'); # this is needed because use strict
if($fh) {
open OUT, ">/tmp/output.gif" || die "cannot open: $!";
binmode OUT; #just in case you are under windows
print $q->header('image/gif');
my $data;
while(read($fh,$data,1024)) {
print $data;
print OUT $data;
}
close OUT;
}
else {
print $q->header();
print $q->start_html();
print $q->h1('no upload file');
print $q->end_html();
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.