The file submission page has been generated, and the following task is clear: Save the submitted file contents to the server.
Here are two ways to accomplish this:
1. Use PHP to Save:
We first define a file Save function fup () it has two parameters:
$filename: File contents
$fname: File name (include path)
The rest is to write a loop to write the file to the server sequentially. Here is a brief explanation:
PHP's handling of uploading files is this: If the submitted file box I am FILE0, then the file content submitted to PHP is stored in the variable $file 0, and the file name is stored in the $file 0_name. So what I'm going to do in this loop is to break up the submission of the commit page and see the code below for the implementation process.
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 "
";
Fup ($ $FFNN, $ $ffpath. $ $ffnnname); //".. /www/test/tmp/"
}
?>
----------------------------------------------------------------------
2. Use PERL to Save:
They are implemented exactly the same way, not much here, see the code:
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".
"Your Web browser cannot upload files. Sorry.";
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".
" <title>411 411 Size Not allowed</title>
You got big problem. Try again.
n ";
Exit 0;
}
Binmode $xfile;
Use file::copy;
Copy ($xfile, $writed. $strNetFname);
}
Sub g_head{
print '
'; print '
File upload results (Upload result) |
'; print '
'; print '
SourceFile: | '; print '
DestFile: | '; print '
Upload | '; print '
'; } Sub g_body{print '
'; print '
'. $xfile. ' | '; print '
'. $writed. $strNetFname. ' | '; print '
Ok! | '; print '
'; } Sub g_bott{print '
';
}
----------------------------------------------------------------------
Please email:gearsoft@netease.com if you have any good suggestions.
"The copyright of this article is owned by author Gearsoft and house Orso near net, if need to reprint, please indicate author and source"
http://www.bkjia.com/PHPjc/316779.html www.bkjia.com true http://www.bkjia.com/PHPjc/316779.html techarticle The file Submission page has been generated, and the following task is clear: Save the submitted file contents to the server. Here we have two ways to achieve this function: 1. Use PHP to save ...