用 perl 实现文件上传

王朝perl·作者佚名  2006-11-24
宽屏版  字体: |||超大  

示例的 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 Internet 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

= "/home/path/to/directory";

## Do you wish to allow all file types? yes/no (no capital letters)

= "yes";

## If the above = "no"; then which is the only extention to allow?

## Remember to have the LAST 4 characters i.e. .ext

= ".gif";

## The page you wish it to forward to when done:

## I.E. http://www.mydomainname.com/thankyou.html

= "http://www.perlservices.com/";

################################################

################################################

## DO NOT EDIT OR COPY BELOW THIS LINE ##

################################################

################################################

use CGI;

= 1;

while ( != 11) {

my = new CGI;

my = ->param("FILE");

if ( ne "") {

my = ;

=~ s!^.*(\\|\/)!!;

= ;

if ( ne "yes") {

if (lc(substr(,length() - 4,4)) ne ){

= "yes";

}

}

if ( ne "yes") {

open (OUTFILE, ">/");

print "/<br>";

while (my = read(, my , 1024)) {

print OUTFILE ;

}

close (OUTFILE);

}

}

++;

}

print "Content-type: text/html\n";

print "Location:\n\n";

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有