示例的 html 文件如下:
<html>
<body>
<form method="post" action="psupload.cgi" enctype="multipart/form-data">
file 1:
<input type="file" name="file1">
<br>
file 2:
<input type="file" name="file2">
<br>
<input type="submit" value="upload!">
</form>
</body>
</html>
后台的 perl 程序如下:
#!/usr/bin/perl
#######################################
## perl services upload helper v1.0 ##
## http://www.perlservices.com ##
## perlservices@perlservices.com ##
## ###########################################
## you should carefully read all of the following terms and conditions ##
## before using this program. your use of this software indicates your ##
## acceptance of this license agreement and warranty. ##
## this program is being distributed as freeware. it may be used ##
## free of charge, but not modified below the line specified. this copyright ##
## must remain intact. ##
## ##
## by using this program you agree to indemnify perl services from any ##
## liability. ##
## ##
## selling the code for this program without prior written consent is ##
## expressly forbidden. obtain permission before redistributing this ##
## program over the inte.net or in any other medium. in all cases the ##
## copyright must remain intact. ##
## ##
## there are security hazards involved with this script. read the readme file##
## before using the script. ##
################################################################################
##
## start setting up options here:
## your path to where you want your files uploaded.
## note: no trailing slash
$basedir = "/home/path/to/directory";
## do you wish to allow all file types? yes/no (no capital letters)
$allowall = "yes";
## if the above = "no"; then which is the only extention to allow?
## remember to have the last 4 characters i.e. .ext
$theext = ".gif";
## the page you wish it to forward to when done:
## i.e. http://www.mydomainname.com/thankyou.html
$donepage = "http://www.perlservices.com/";
################################################
################################################
## do not edit or copy below this line ##
################################################
################################################
use cgi;
$onnum = 1;
while ($onnum != 11) {
my $req = new cgi;
my $file = $req->param("file$onnum");
if ($file ne "") {
my $filename = $file;
$filename =~ s!^.*(\\\/)!!;
$newmain = $filename;
if ($allowall ne "yes") {
if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){
$filenotgood = "yes";
}
}
if ($filenotgood ne "yes") {
open (outfile, ">$basedir/$filename");
print "$basedir/$filename<br>";
while (my $bytesread = read($file, my $buffer, 1024)) {
print outfile $buffer;
}
close (outfile);
}
}
$onnum++;
}
print "content-type: text/html\n";
print "location:$donepage\n\n";
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器