Home > Article > Backend Development > Let you upload 1000 files at the same time (2)_PHP tutorial
Now that the file submission page has been generated, the following task is clear: save the submitted file content to the server.
Below we use two methods to implement this function:
1. Use PHP to save:
We first define a file saving function fup() which has two parameters:
$filename: file content
$fname: file name (including path)
The rest is to write a loop to write the files to the server in sequence. Here is a brief explanation:
PHP handles uploaded files like this: If the submitted file box is file0, then the content of the file submitted to PHP is saved in the variable $file0, and the file name is saved in $file0_name middle. In this way, what I have to do in this loop is to decompose the content submitted on the submission page. Please 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;
$ffnn,$$ffpath.$$ffnnname); //"../www/test/tmp/"
}
?>
------------ -------------------------------------------------- --------
2. Use PERL to save:
The principles of their implementation are exactly the same. I won’t go into details here. Please look at 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" .
"
文件上传结果(Upload Result) | ||
SourceFile: | ';DestFile: | ';Upload | ';
'.$xfile .' | ';'.$writed.$strNetFname.' | ';OK! | ';