1 #!/usr/local/bin/perl -w
5 use CGI::Carp qw/fatalsToBrowser/;
8 print start_html("File Upload Example");
9 print strong("Version "),$CGI::VERSION,p;
11 print h1("File Upload Example"),
12 'This example demonstrates how to prompt the remote user to
13 select a remote file for uploading. ',
14 strong("This feature only works with Netscape 2.0 browsers."),
16 'Select the ',cite('browser'),' button to choose a text file
17 to upload. When you press the submit button, this script
18 will count the number of lines, words, and characters in
21 @types = ('count lines','count words','count characters');
23 # Start a multipart form.
24 print start_multipart_form(),
25 "Enter the file to process:",
26 filefield('filename','',45),
28 checkbox_group('count',\@types,\@types),
30 reset,submit('submit','Process File'),
33 # Process the form if there is a file name entered
34 if ($file = param('filename')) {
35 $tmpfile=tmpFileName($file);
36 $mimetype = uploadInfo($file)->{'Content-Type'} || '';
40 h4("MIME Type:",em($mimetype));
42 my($lines,$words,$characters,@words) = (0,0,0,0);
45 $words += @words=split(/\s+/);
46 $characters += length($_);
49 grep($stats{$_}++,param('count'));
51 print strong("Lines: "),$lines,br if $stats{'count lines'};
52 print strong("Words: "),$words,br if $stats{'count words'};
53 print strong("Characters: "),$characters,br if $stats{'count characters'};
55 print strong("No statistics selected.");
59 # print cite("URL parameters: "),url_param();
62 a({href=>"../cgi_docs.html"},"CGI documentation"),
65 a({href=>'/~lstein'},"Lincoln D. Stein")),
67 'Last modified July 17, 1996',