PERL CODE:
#!c:\perl\bin\perl.exe $| = 1; #Not sure what it does, but it works :) #starts the cgi.pm mod use CGI qw(:standard); $cgi = new CGI; #get the form data $file1 = $cgi->param('file1'); $file2 = $cgi->param('file2'); $file3 = $cgi->param('file3'); $file4 = $cgi->param('file4'); #directory you want to upload to $dir = "c:/windows/desktop"; push @files, ("$file1","$file2","$file3","$file4"); foreach $file (@files) { #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'}; $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"); print $cgi->header(); #prints the header stuff #$bytesread holds the value of the size of the #file in bytes. Useful if you want to restrict #size of uploaded files print "Successful Upload<p>File:$file ($file_type, $bytesread bytes)<B +R>\n"; } exit; #exit's script
HTML CODE:
<HTML> <HEAD> <TITLE>Upload a File Through the WWW</TITLE> </HEAD> <BODY BGCOLOR="#FFFFF"> <H1><TT><B>File Upload!</B></TT></H1> <P> To upload a file through the WWW, fill out the form below: <form method="POST" action="upload.cgi" ENCTYPE="multipart/form-data"> + <body bgcolor=black text=black> File: <input type="file" name="file1"><br> File: <input type="file" name="file2"><br> File: <input type="file" name="file3"><br> File: <input type="file" name="file4"><br> <input type="submit" value="UPLOAD"> </form> </BODY> </HTML>
In reply to Uploading Script Errors by Stamp_Guy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |