1N/A#!/usr/local/bin/perl -w
1N/A
1N/Ause strict 'refs';
1N/Ause lib '..';
1N/Ause CGI qw(:standard);
1N/Ause CGI::Carp qw/fatalsToBrowser/;
1N/A
1N/Aprint header();
1N/Aprint start_html("File Upload Example");
1N/Aprint strong("Version "),$CGI::VERSION,p;
1N/A
1N/Aprint h1("File Upload Example"),
1N/A 'This example demonstrates how to prompt the remote user to
1N/A select a remote file for uploading. ',
1N/A strong("This feature only works with Netscape 2.0 or greater, or IE 4.0 or greater."),
1N/A p,
1N/A 'Select the ',cite('browser'),' button to choose a text file
1N/A to upload. When you press the submit button, this script
1N/A will count the number of lines, words, and characters in
1N/A the file.';
1N/A
1N/Amy @types = ('count lines','count words','count characters');
1N/A
1N/A# Start a multipart form.
1N/Aprint start_multipart_form(),
1N/A "Enter the file to process:",
1N/A filefield('filename','',45),
1N/A br,
1N/A checkbox_group('count',\@types,\@types),
1N/A p,
1N/A reset,submit('submit','Process File'),
1N/A endform;
1N/A
1N/A# Process the form if there is a file name entered
1N/Aif (my $file = param('filename')) {
1N/A my %stats;
1N/A my $tmpfile=tmpFileName($file);
1N/A my $mimetype = uploadInfo($file)->{'Content-Type'} || '';
1N/A print hr(),
1N/A h2($file),
1N/A h3($tmpfile),
1N/A h4("MIME Type:",em($mimetype));
1N/A
1N/A my($lines,$words,$characters,@words) = (0,0,0,0);
1N/A while (<$file>) {
1N/A $lines++;
1N/A $words += @words=split(/\s+/);
1N/A $characters += length($_);
1N/A }
1N/A close $file;
1N/A grep($stats{$_}++,param('count'));
1N/A if (%stats) {
1N/A print strong("Lines: "),$lines,br if $stats{'count lines'};
1N/A print strong("Words: "),$words,br if $stats{'count words'};
1N/A print strong("Characters: "),$characters,br if $stats{'count characters'};
1N/A } else {
1N/A print strong("No statistics selected.");
1N/A }
1N/A}
1N/A
1N/A# print cite("URL parameters: "),url_param();
1N/A
1N/Aprint hr(),
1N/A a({href=>"../cgi_docs.html"},"CGI documentation"),
1N/A hr,
1N/A address(
1N/A a({href=>'/~lstein'},"Lincoln D. Stein")),
1N/A br,
1N/A 'Last modified July 17, 1996',
1N/A end_html;
1N/A