Add a few missing files, update MANIFEST.
[p5sagit/p5-mst-13.2.git] / lib / CGI / eg / file_upload.cgi
CommitLineData
424ec8fa 1#!/usr/local/bin/perl -w
54310121 2
71f3e297 3use strict 'refs';
424ec8fa 4use lib '..';
54310121 5use CGI qw(:standard);
424ec8fa 6use CGI::Carp qw/fatalsToBrowser/;
54310121 7
8print header();
9print start_html("File Upload Example");
10print strong("Version "),$CGI::VERSION,p;
11
12print h1("File Upload Example"),
13 'This example demonstrates how to prompt the remote user to
14 select a remote file for uploading. ',
3538e1d5 15 strong("This feature only works with Netscape 2.0 or greater, or IE 4.0 or greater."),
54310121 16 p,
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
20 the file.';
21
71f3e297 22my @types = ('count lines','count words','count characters');
54310121 23
24# Start a multipart form.
25print start_multipart_form(),
26 "Enter the file to process:",
27 filefield('filename','',45),
28 br,
29 checkbox_group('count',\@types,\@types),
30 p,
31 reset,submit('submit','Process File'),
32 endform;
33
34# Process the form if there is a file name entered
71f3e297 35if (my $file = param('filename')) {
36 my %stats;
37 my $tmpfile=tmpFileName($file);
38 my $mimetype = uploadInfo($file)->{'Content-Type'} || '';
54310121 39 print hr(),
40 h2($file),
424ec8fa 41 h3($tmpfile),
42 h4("MIME Type:",em($mimetype));
43
54310121 44 my($lines,$words,$characters,@words) = (0,0,0,0);
45 while (<$file>) {
46 $lines++;
47 $words += @words=split(/\s+/);
48 $characters += length($_);
49 }
50 close $file;
51 grep($stats{$_}++,param('count'));
52 if (%stats) {
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'};
56 } else {
57 print strong("No statistics selected.");
58 }
59}
60
424ec8fa 61# print cite("URL parameters: "),url_param();
62
54310121 63print hr(),
64 a({href=>"../cgi_docs.html"},"CGI documentation"),
65 hr,
66 address(
67 a({href=>'/~lstein'},"Lincoln D. Stein")),
68 br,
69 'Last modified July 17, 1996',
70 end_html;
71