Let you Upload 1000 files at the same time (2). read this article and let you upload 1000 files at the same time (2). The File submission page has been generated. the following task is very clear: save the submitted file content to the server. The following two methods are used to implement this function: 1. use PHP to save: We first define a file storage function fup () which has two parameters "> <LINKhref =" http: // w file submission page already generated, the following task is clear: save the submitted file content to the server.
The following two methods are used to implement this function:
1. use PHP to save:
We first define a file storage function fup () which has two parameters:
$ Filename: file content
$ Fname: file name (including path)
The rest is to write a loop to write files to the server in sequence. Here is a brief description:
PHP processes uploaded files as follows: if the submitted file box is file0, the file content submitted to PHP is saved in the variable $ file0, the file name is saved in $ file0_name. In this way, all I need to do in this loop is to break down the content submitted on the submit page. for the implementation process, see the following code.
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:
The implementation principles are exactly the same. For more information, 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 "sorting ing 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 ".
" 411 411 Size Not AllowedYou got big problem. Try again.N ";
Exit 0;
}
Binmode $ xfile;
Use File: Copy;
Copy ($ xfile, $ writed. $ strNetFname );
}
Sub g_head {
Print'
';Print'
File 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'
';
}
----------------------------------------------------------------------
If you have good suggestions, please Email: gearsoft@netease.com
[This article is copyrighted by the authors gearsoft and Aesop. if you need to reprint it, please indicate the author and its source]