#! perl # # test of file uploading # CGI.pm versions before 2.74 may require a patch to make file # uploading work on VMS. # use CGI; $CRINOID::Reuse = 1; $q = new CGI; print $q->header('text/html'); print $q->start_html('Test File uploading'); ask_upload($q); proc_upload($q); print $q->end_html; sub ask_upload { my $q = shift; print "

Request upload

",$q->start_multipart_form(); print "Client file to upload: ", $q->filefield(-name=>'uploaded_file', -default=>'starting value', -size=>20, -maxlength=>80); print "

requested filename on server: "; print $q->textfield(-name=>'filename', -default=>'', -size=>20, -maxlength=>80); print " ",$q->submit(-name=>'Upload'),$q->endform(),"

\n"; } # # works now, with mod to OPCODE.XS to handle _ & recent changes # in CGI.pm # sub proc_upload { my $q = shift; if (!defined($q->param('uploaded_file'))) { print "


No file upload request\n"; return 1; } my $fn = $q->param('filename'); my $f = $q->param('uploaded_file'); print "
\n"; print "
Filename on client:$f\n"; print "
Filename on server:$fn
\n"; print "

File contents:

\n";
    while (<$f>) {
        s/\&/&/g;           ### escape any html stuff
        s/\
\n"; my $tmp = $q->tmpFileName($f); ## MUST clean up afterwards! close $f; # close the i/o unlink $tmp if $tmp; # get rid of tempfile return 0; }