This is straight from the examples section of the CGI.pm documentation:
# Process the form if there is a file name entered
if (my $file = param('filename')) {
my %stats;
my $tmpfile=tmpFileName($file);
my $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 c
+haracters'};
} else {
print strong("No statistics selected.");
}
}
Of course, this is for processing a text file. To get information from an uploaded binary file, I do a stat() on the filehandle.
$filename = $query->param('uploaded_file');
@stats=stat $filename;
$size_of_file=$stats[7];
Hope this helps!
Oakbox
"If what I'm saying doesn't make sense, that's because sense cannot be made, it's something that must be sensed"-J.S. Hall |