Stamp_Guy has asked for the wisdom of the Perl Monks concerning the following question:
#!C:\perl\bin\perl.exe -w $| = 1; use CGI qw(:standard); $cgi = new CGI; $path = "c:\\windows\\desktop"; print<<EOT; <CENTER><TABLE width="766" border="0" cellspacing="0" cellpadding="0"> <TR><TD colspan="4"><b>The following files were uploaded:<BR> </b +></TD></TR> <TR bgcolor="black"> <TD> </TD> <TD><FONT color="white"><B>FILE:</B></FONT></TD> <TD><FONT color="white"><B>DETAILS:</B></FONT></TD> <TD><FONT color="white"><B>STATUS:</B></FONT></TD> </TR> 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; <TR> <TD> </TD> <TD valign="top"> <B><FONT color=#000080>$file</FONT></B> </TD><TD></TD><TD> <B><FONT color="red">UPLOAD FAILED!*</FONT></B><P> </TD></TR> EOT $failed = "1"; open (LOGFILE, ">>c:\\windows\\desktop\\logfile.html") || die "Can +'t open log file"; $name = uc($name); print LOGFILE "<TR><TD colspan=5><CENTER><b>$name <font color=red> +UPLOAD FAILED</b></font><CENTER></TD></TR>"; 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 filenam +e $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 "<TR><TD> </TD><TD><font color=#000080><b>$file +</b></font></b></TD><TD><b> ($file_type, $bytesread bytes)</b></TD><T +D><B>Successfully Uploaded</B></TD></TR>\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 "<TR><TD colspan=5>* A file with the same name already exists. +Please rename the file and try again.</TD></TR>"; } print<<EOT; </TABLE></CENTER> EOT }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid) Re: 52K maximum file upload?
by Ovid (Cardinal) on Nov 29, 2000 at 05:31 UTC | |
by Stamp_Guy (Monk) on Nov 29, 2000 at 06:15 UTC | |
by Ovid (Cardinal) on Nov 29, 2000 at 07:13 UTC | |
|
Re: 52K maximum file upload?
by chromatic (Archbishop) on Nov 29, 2000 at 05:21 UTC | |
|
Re: 52K maximum file upload?
by chipmunk (Parson) on Nov 29, 2000 at 07:42 UTC | |
by Anonymous Monk on Nov 29, 2000 at 11:03 UTC |