#!C:\perl\bin\perl.exe -w $| = 1; use CGI qw(:standard); $cgi = new CGI; $path = "c:\\windows\\desktop"; print< EOT # Get the form data $file1 = $cgi->param('file1'); $file2 = $cgi->param('file2'); $file3 = $cgi->param('file3'); $file4 = $cgi->param('file4'); $file5 = $cgi->param('file5'); $file6 = $cgi->param('file6'); $file7 = $cgi->param('file7'); $file8 = $cgi->param('file8'); $file9 = $cgi->param('file9'); $file10 = $cgi->param('file10'); $file11 = $cgi->param('THUMBNAIL_PHOTO'); $file12 = $cgi->param('LARGE_PHOTO'); $file13 = $cgi->param('FLYER_URL'); #directory you want to upload to $dir = "c:/windows/desktop"; push @files, ($file1,$file2,$file3,$file4,$file5,$file6,$file7,$file8,$file9,$file10,$file11,$file12,$file13); foreach $file (@files) { if ($file ne "") { $name=$file; $name =~ s/.:\\.*\\//; if (-e "c:\\windows\\desktop\\$name") { $file =~ s/.:\\.*\\//; $file = uc($file); print< EOT $failed = "1"; open (LOGFILE, ">>c:\\windows\\desktop\\logfile.html") || die "Can't open log file"; $name = uc($name); print LOGFILE ""; close(LOGFILE); } else { #file_type not necessary but can be useful info #if your wanting to limit uploads to a certain #type of file $file_type = $cgi->uploadInfo($file)->{'Content-Type'}; #directory you want to upload to $dir = "c:/windows/desktop"; $file=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filename $name = $2; #My understanding gets real iffy from here on in #however it does work in the exact format below open(LOCAL, ">$dir/$name") or die $!; #open file undef $bytesread; undef $buffer; # binmode is only necessary on win32 servers but #it won't hurt with unix so might as well leave it binmode LOCAL; while ($bytes = read($file,$buffer,1024)) { $bytesread += $bytes; print LOCAL $buffer; } close($file); close(LOCAL); chmod(0666,"$dir\/$name"); #$bytesread holds the value of the size of the #file in bytes. Useful if you want to restrict #size of uploaded files $file =~ s/.:\\.*\\//; $file = uc($file); print "\n"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $min=sprintf("%02d", $min); $sec=sprintf("%02d", $sec); } } } if ($failed eq "1") { print ""; } print< EOT }
The following files were uploaded:
 
    FILE: DETAILS: STATUS:
  $file UPLOAD FAILED!*

$name UPLOAD FAILED
   $file ($file_type, $bytesread bytes)Successfully Uploaded
* A file with the same name already exists. Please rename the file and try again.