Home: Perl Programming Help: Intermediate:
How to do a fileupload



speicher
Deleted

Jan 27, 2000, 10:03 PM


Views: 4986
How to do a fileupload

I'm trying to do a fileupload using the CGI.pm in Perl. I'm using Perl V5 on the OS/390. I keep getting a "malformed multipart POST" error. Below is a snippet of my code to show I'm using a multipart form.
It's when I select the Process file button, that the above error occurs on the server. Any help is greatly appreciated!

use lib '/usr/local/lib/perl5';
use CGI qw(:all);
print "Content-Type: text/html\n\n";
print start_html("File Upload Example");
# Start a multipart form.
print start_multipart_form(),
"Enter the file to process:",
filefield('filename','',45),
br,
checkbox_group('count',\@types,\@types),
p,
reset,submit('submit','Process File'),
endform;

# Process the form if there is a file name entered
if ($file = param('filename')) {
$tmpfile=tmpFileName($file);
$mimetype = uploadInfo($file)->{'Content-Type'} | | '';
print hr(),
h2($file),
h3($tmpfile),
h4("MIME Type:",em($mimetype));

my($lines,$words,$characters,@words) = (0,0,0,0);
while (<$file> ) {
$lines++;
$words += @words=split(/\s+/);
$characters += length($_);
}
close $file;
grep($stats{$_}++,param('count'));
if (%stats) {
print strong("Lines: "),$lines,br if $stats{'count lines'};
print strong("Words: "),$words,br if $stats{'count words'};
print strong("Characters: "),$characters,br if $stats{'count characters'};
} else {
print strong("No statistics selected.");
}
}



Jasmine
Administrator

Feb 1, 2000, 8:12 AM


Views: 4986
Re: How to do a fileupload

Based on the other file uploading programs I've seen, there's a few things that look awry in the code.

You may wish to check out the WebReview "CGI File Uploading" Tutorial and the documentation for CGI.pm