#! /usr/bin/perl -Tw # # This script, "soa.cgi", was written by Joe Freeman for the IAEA-TM # "Submission of Abstracts" page, based upon the script "upload.pl" # by Muhammad Muquit. # It is designed to be run from Web page # http://fusion.gat.com/conferences/iaea-tm-computing/exchange/. # Variables beginning with a capital letter are global variables. use strict ; use CGI ; $| = 1 ; my $query = new CGI ; my $Overwrite = 0 ; my $Debug = 0 ; my $Title = "Submission of Abstracts > Upload a File" ; my $Upload_path = "/web/conferences/iaea-tm-computing/exchange/incoming/" ; print $query->header ; &printHTMLHeader ; if ( $query->param ) { &doWork() ; } else { &printForm() ; } sub printForm { print '
' ; print $query->start_multipart_form, "\n" ; # upload print '" ; # submit print '\n" ; print $query->endform, "\n" ; print "
Upload this file:' ; print $query->filefield(-name => 'upload_file', -size => 48, -maxlength => 96) ; print "
' ; print $query->submit(-label => 'upload', -value => ' Upload Now ') ; print "
" ; } sub printHTMLHeader { print $query->start_html(-title => "$Title", -bgcolor => "#ffffff", -text => "#000000") ; } sub doWork { my $error_message = '' ; &printForm() ; if ( $error_message ) { &printError($error_message) ; return ; } # now upload file &uploadFile() ; if ( $Debug == 1 ) { my @all = $query->param ; my $name ; foreach $name (@all) { print "DEBUG: $name = ", $query->param($name), "
" ; } } } sub printError { my $error_message = shift ; print <

Error: $error_message
Return to the Submission of Abstracts page, or try another file upload.

EOF ; } sub uploadFile { my $time_took ; my $start_time ; my $bytes_read = 0 ; my $size = 0 ; my $buffer = '' ; my $filepath = '' ; my $filename = '' ; my $pathname = '' ; $filepath = $query->param('upload_file') ; if ( $filepath =~ /([^\/\\]+)$/ ) { $filename = "$1" ; } else { $filename = "$filepath" ; } $filename =~ s/\s+/_/g ; $filename =~ tr/A-Z/a-z/ ; $pathname = "$Upload_path" . "$filename" ; print "DEBUG: filename = $filename
\n" if $Debug ; print "DEBUG: pathname = $pathname
\n" if $Debug ; if ( ! $filename ) { &printError("You must provide the name of a file to upload.") ; return ; } if ( $Overwrite == 0 ) { if ( -e $pathname ) { &printError("A file named $filename already exists. It may not be overwritten.") ; return ; } } if ( ! open(WFD,">$pathname") ) { &printError("Error opening file for writing.") ; return ; } $start_time = time() ; while ( $bytes_read = read($filepath,$buffer,4096) ) { $size += $bytes_read ; binmode WFD ; print WFD $buffer ; } print "DEBUG: size = $size
\n" if $Debug ; close(WFD) ; if ( (stat $pathname)[7] <= 0 ) { unlink($pathname) ; &printError("File $filename could not be uploaded. Are you sure it exists?") ; return ; } else { chmod 0333, $pathname ; $time_took = time() - $start_time ; print <

File $filename of size $size bytes was successfully uploaded.
Return to the Submission of Abstracts page, or try another file upload.

EOF ; } }