示例的 HTML 文件如下:rjvLinux联盟
<html>rjvLinux联盟
<body>rjvLinux联盟
<form method="POST" action="psupload.cgi" ENCTYPE="multipart/form-data">rjvLinux联盟
File 1: rjvLinux联盟
<input type="file" name="FILE1">rjvLinux联盟
<br>rjvLinux联盟
File 2: rjvLinux联盟
<input type="file" name="FILE2">rjvLinux联盟
<br>rjvLinux联盟
<input type="submit" value="Upload!">rjvLinux联盟
</form>rjvLinux联盟
</body>rjvLinux联盟
</html>rjvLinux联盟
后台的 Perl 程序如下:
#!/usr/bin/perlrjvLinux联盟
#######################################rjvLinux联盟
## Perl Services Upload Helper v1.0 ##rjvLinux联盟
## http://www.perlservices.com ##rjvLinux联盟
## perlservices@perlservices.com ##rjvLinux联盟
## ###########################################rjvLinux联盟
## You should carefully read all of the following terms and conditions ##rjvLinux联盟
## before using this program. Your use of this software indicates your ##rjvLinux联盟
## acceptance of this license agreement and warranty. ##rjvLinux联盟
## This program is being distributed as freeware. It may be used ##rjvLinux联盟
## free of charge, but not modified below the line specified. This copyright ## rjvLinux联盟
## must remain intact. ##rjvLinux联盟
## ##rjvLinux联盟
## By using this program you agree to indemnify Perl Services from any ##rjvLinux联盟
## liability. ##rjvLinux联盟
## ##rjvLinux联盟
## Selling the code for this program without prior written consent is ##rjvLinux联盟
## expressly forbidden. Obtain permission before redistributing this ##rjvLinux联盟
## program over the Internet or in any other medium. In all cases the ##rjvLinux联盟
## copyright must remain intact. ##rjvLinux联盟
## ##rjvLinux联盟
## There are security hazards involved with this script. Read the readme file##rjvLinux联盟
## before using the script. ##rjvLinux联盟
###################################################
##rjvLinux联盟
## Start setting up options here:
## Your path to where you want your files uploaded.rjvLinux联盟
## Note: NO trailing slashrjvLinux联盟
$basedir = "/home/path/to/directory";
## Do you wish to allow all file types? yes/no (no capital letters)rjvLinux联盟
$allowall = "yes";
## If the above = "no"; then which is the only extention to allow?rjvLinux联盟
## Remember to have the LAST 4 characters i.e. .extrjvLinux联盟
$theext = ".gif";
## The page you wish it to forward to when done:rjvLinux联盟
## I.E. http://www.mydomainname.com/thankyou.htmlrjvLinux联盟
$donepage = "http://www.perlservices.com/";rjvLinux联盟
################################################rjvLinux联盟
################################################rjvLinux联盟
## DO NOT EDIT OR COPY BELOW THIS LINE ##rjvLinux联盟
################################################rjvLinux联盟
################################################
use CGI; rjvLinux联盟
$onnum = 1;
while ($onnum != 11) {rjvLinux联盟
my $req = new CGI; rjvLinux联盟
my $file = $req->param("FILE$onnum"); rjvLinux联盟
if ($file ne "") {rjvLinux联盟
my $fileName = $file; rjvLinux联盟
$fileName =~ s!^.*(\\|\/)!!; rjvLinux联盟
$newmain = $fileName;rjvLinux联盟
if ($allowall ne "yes") {rjvLinux联盟
if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){rjvLinux联盟
$filenotgood = "yes";rjvLinux联盟
}rjvLinux联盟
}rjvLinux联盟
if ($filenotgood ne "yes") { rjvLinux联盟
open (OUTFILE, ">$basedir/$fileName"); rjvLinux联盟
print "$basedir/$fileName<br>";rjvLinux联盟
while (my $bytesread = read($file, my $buffer, 1024)) { rjvLinux联盟
print OUTFILE $buffer; rjvLinux联盟
} rjvLinux联盟
close (OUTFILE); rjvLinux联盟
}rjvLinux联盟
}rjvLinux联盟
$onnum++;rjvLinux联盟
}
print "Content-type: text/html\n";rjvLinux联盟
print "Location:$donepage\n\n";