#!/usr/bin/perl -w
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#NAME
# uploadform.cgi - CGI sanity test
#
#SYNOPSIS
# http://host.com.ain:port/CGI/uploadform.cgi
#
#DESCRIPTION
# This is a CGI script that produces a simple form for uploading
# files (pictures in our application) to a local directory. The
# form invokes the uploadpic.cgi program to accept the picture
# and store it in our pic directory.
#
#OPTIONS
#
#FILES
#
#BUGS
#
#SEE ALSO
#
#AUTHOR John Chambers
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
$| = 1;
($P = $0) =~ s"^.*/""; # Remove directory from program name
$V = $ENV{"V_$P"} || 2; # Verbose level
($hostname = `/bin/hostname`) =~ s/^\s*([-.\w]*)([\r\s]*)$/$1/; # Full host name
($host = $1) =~ s/\..*//; # Extract first field of name
($cwd = `/bin/pwd`) =~ s/[\r\s]*$//;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
use CGI;
$q = new CGI;
print $q -> header;
print $q -> start_html(-title => "An upload form");
print $q -> h1("Demo: upload form");
print $q -> start_multipart_form(-action => "UploadHandler.cgi");
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
print "Type a description of the file: ",
$q->textfield(-name => 'description', -size => 60),
$q->br;
print "Where is the file on your machine? ",
$q->filefield(-name => 'picname'),
$q->br;
print "Type the desired file name: ",
$q->textfield(-name => 'filename',-size => 40),
$q->br;
print $q -> submit;
if ($V>1) {
print "
Current pictures:\n";
@pics = `ls pic/*`;
$pics = int(@pics);
print "We have $pics pictures.\n";
print "\n";
for $pic (@pics) {
if (($dir,$name) = ($pic =~ m"(.*)/+([^/]+)[\r\s]*$")) {
print "\n";
print " \n";
print " \n";
print "\n";
}
}
print "\n";
}
print $q -> end_form;
exit 0;