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