日期:2010-11-27 浏览次数:20719 次
下面我们用两种方法来实现这个功能:
1. 用 PHP 来保存:
fileup.PHP
----------------------------------------------------------------------
<?
function fup($filename,$fname)
{ If($filename != "none") {
copy($filename,$fname);
unlink($filename);
}
}
for($i=0;$i<$cnt;$i++)
{
$ffnn="file".$i;
$ffnnname=$ffnn."_name";
$ffpath="path".$i;
//print $$ffnn;
print $$ffnnname;
print "<br>";
fup($$ffnn,$$ffpath.$$ffnnname); //"../www/test/tmp/"
}
?>
----------------------------------------------------------------------
2. 用 PERL 来保存:
它们实现的原理完全一样,在此不多说,请看代码:
fileup.CGI(fileup.pl)
----------------------------------------------------------------------
#!/usr/bin/perl
use CGI qw/:standard/;
if ($ENV{'CONTENT_TYPE'} !~ /multipart/form-data/) {
print "Cache-Control: no-cachenPragma: no-cachen" .
"Content-Type: text/HTMLnn" .
"<HTML><body>Your web browser cannot upload files. Sorry.</body></HTML>";
exit 0;
}
$cntfile=param('cnt');
print header;
print start_HTML;
#print "Receiving Please wait....";
&g_head;
#$writed = '../www/test/tmp/';
for ($i=0;$i<$cntfile;$i++){
$paramfile = 'file'.$i;
$parampath='path'.$i;
$writed=param($parampath);
&upfile;
&g_body;
}
&g_bott;
#<<<<<<<<<<<<<<<<<<<<<以下为自定义过程<<<<<<<<<<<<<<<<<<<<<<<<<
sub upfile
{
$maxdata = 512000;
# $writed = '../www/test/tmp/';
$strRFname=reverse $xfile;
$intIndex=index($strRFname,'\');
$strNetFname=substr($strRFname,0,$intIndex);
$strNetFname=scalar reverse $strNetFname;
if((stat $xfile)[7]>$maxdata){
print "Status: 411 Size Not Allowedn" .
"Content-Type: text/HTMLnAllow: POSTnn" .
"<HTML><head><title>411 411 Size Not Allowed</title></head><body><h1> You got big problem. Try again.</h1></body></HTML>n";
exit 0;
}
binmode $xfile;
use file::Copy;
copy($xfile,$writed.$strNetFname);
}
sub g_head{
print '<table border=1 align=center>';
print '<tr><td colspan=3 align=center>文件上传结果(Upload Result)</td></tr>';
print '<tr align=center>';
print ' <td>Sourcefile:</td>';
print ' <td>Destfile:</td>';
print ' <td>Upload&l