programming-examples/perl/CGI/CGI file upload example.pl
2019-11-15 12:59:38 +01:00

38 lines
751 B
Perl

#!/usr/local/bin/perl
use CGI;
$co = new CGI;
if (!$co->param())
{
print
$co->header,
$co->start_html('CGI File Upload Example'),
$co->center
(
$co->start_multipart_form,
$co->filefield(-name=>'filename', -size=>30),
$co->br,
$co->submit(-value=>'Upload'),
$co->reset,
$co->end_form
),
$co->hr;
} else {
print
$co->header,
$co->start_html('');
$file = $co->param('filename');
@data = <$file>;
foreach (@data) {
s/\n/<br>/g;
}
print
$co->center($co->h2("Here's the contents of $file...")),
"@data";
}
print $co->end_html;