#!/usr/local/bin/perl # Use JavaScript to validate fill-out # forms. use CGI qw(:standard); # Here's the javascript code that we include in the document. $JSCRIPT=<'Untitled Document', -head => meta({ -http_equiv => 'Content-Type', -content => 'text/html; charset=iso-8859-1'}), -script=>$JSCRIPT); print_prompt(); print_response() if (param); print end_html; sub print_prompt { #post return print start_multipart_form(-name=>'form1', -onSubmit=>"validateForm()", -method=>"post"),"\n"; print table({-border=>0,-width=>"75%"},"\n", Tr(td({-width=>"32%"},div({-align=>"right"},'First Name: ')) ,td({-width=>"68%"},input({-type=>'text',-name=>'firstname'})) ), Tr( [ td([div({-align=>"right"},'Last Name:'),input({-type=>'text',-name=>'lastname'})]), td([div({-align=>"right"},'Email Address: '),input({-type=>'text',-name=>'email'})]), td([div({-align=>"right"},'File One: '),input({-type=>'file',-name=>'fileone'})]), td([div({-align=>"right"},'File Two: '),input({-type=>'file',-name=>'filetwo'})]), td([div({-align=>"right"},'File Three: '),input({-type=>'file',-name=>'filethree'})]) ]) ); print hidden('state','init'); print submit(),"\n"; print end_form; } sub print_response { return unless(param('firstname')); return unless(param('lastname')); $value = param('email'); return unless($value =~/@/); my $i=0; my $SAVE_DIRECTORY = "c:/temp"; foreach $key (param()) { next unless $key =~ /file/; my $file_name = param($key); next unless length($file_name)>0; $file_name =~ /([^\\\/]+)$/; $SaveFilename = $1; unless (open(OUTFILE, ">$SAVE_DIRECTORY/$SaveFilename")){ print "Cannot open file $SAVE_DIRECTORY/$SaveFilename for upload.\n",p;; next; } while ($Bytes = read($file_name,$Buffer,1024)) { print OUTFILE $Buffer; } close(OUTFILE); close($file_name); print "Upload file to $SAVE_DIRECTORY/$SaveFilename.\n",p; $i++; } print "Total file count $i .\n"; }