use CGI
::Carp qw
/fatalsToBrowser/;
print start_html
("File Upload Example");
print strong
("Version "),$CGI::VERSION
,p
;
print h1
("File Upload Example"),
'This example demonstrates how to prompt the remote user to
select a remote file for uploading. ',
strong
("This feature only works with Netscape 2.0 or greater, or IE 4.0 or greater."),
'Select the ',cite
('browser'),' button to choose a text file
to upload. When you press the submit button, this script
will count the number of lines, words, and characters in
my @types = ('count lines','count words','count characters');
# Start a multipart form.
print start_multipart_form
(),
"Enter the file to process:",
filefield
('filename','',45),
checkbox_group
('count',\
@types,\
@types),
reset,submit
('submit','Process File'),
# Process the form if there is a file name entered
if (my $file = param
('filename')) {
my $tmpfile=tmpFileName
($file);
my $mimetype = uploadInfo
($file)->{'Content-Type'} || '';
h4
("MIME Type:",em
($mimetype));
my($lines,$words,$characters,@words) = (0,0,0,0);
$words += @words=split(/\s+/);
$characters += length($_);
grep($stats{$_}++,param
('count'));
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'};
print strong
("No statistics selected.");
# print cite("URL parameters: "),url_param();
a
({href
=>"../cgi_docs.html"},"CGI documentation"),
a
({href
=>'/~lstein'},"Lincoln D. Stein")),
'Last modified July 17, 1996',