[win32] the EXTCONST in sdbm.h breaks SDBM on Borland, since
[p5sagit/p5-mst-13.2.git] / eg / cgi / file_upload.cgi
CommitLineData
54310121 1#!/usr/local/bin/perl
2
3use CGI qw(:standard);
4use CGI::Carp;
5
6print header();
7print start_html("File Upload Example");
8print strong("Version "),$CGI::VERSION,p;
9
10print h1("File Upload Example"),
11 'This example demonstrates how to prompt the remote user to
12 select a remote file for uploading. ',
13 strong("This feature only works with Netscape 2.0 browsers."),
14 p,
15 'Select the ',cite('browser'),' button to choose a text file
16 to upload. When you press the submit button, this script
17 will count the number of lines, words, and characters in
18 the file.';
19
20@types = ('count lines','count words','count characters');
21
22# Start a multipart form.
23print start_multipart_form(),
24 "Enter the file to process:",
25 filefield('filename','',45),
26 br,
27 checkbox_group('count',\@types,\@types),
28 p,
29 reset,submit('submit','Process File'),
30 endform;
31
32# Process the form if there is a file name entered
33if ($file = param('filename')) {
34 $tmpfile=tmpFileName($file);
35 print hr(),
36 h2($file),
37 h3($tmpfile);
38 my($lines,$words,$characters,@words) = (0,0,0,0);
39 while (<$file>) {
40 $lines++;
41 $words += @words=split(/\s+/);
42 $characters += length($_);
43 }
44 close $file;
45 grep($stats{$_}++,param('count'));
46 if (%stats) {
47 print strong("Lines: "),$lines,br if $stats{'count lines'};
48 print strong("Words: "),$words,br if $stats{'count words'};
49 print strong("Characters: "),$characters,br if $stats{'count characters'};
50 } else {
51 print strong("No statistics selected.");
52 }
53}
54
55print hr(),
56 a({href=>"../cgi_docs.html"},"CGI documentation"),
57 hr,
58 address(
59 a({href=>'/~lstein'},"Lincoln D. Stein")),
60 br,
61 'Last modified July 17, 1996',
62 end_html;
63