Of course, this is for processing a text file. To get information from an uploaded binary file, I do a stat() on the filehandle.# 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."); } }
Hope this helps!$filename = $query->param('uploaded_file'); @stats=stat $filename; $size_of_file=$stats[7];
In reply to Re: how to get the sizes of a file when i use CGI.PM to upload it~~?
by oakbox
in thread how to get the sizes of a file when i use CGI.PM to upload it~~?
by swansun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |