Allow you to upload 1000 files simultaneously (2) _ PHP Tutorial

Source: Internet
Author: User
Allow you to upload 1000 files simultaneously (2 ). The following task is clear when the file submission page is generated: save the submitted file content to the server. The following two methods are used to implement this function: 1. use PHP to save the file submission page. 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' ';Print' ';Print' ';Print' ';Print' ';Print' ';}Sub g_body {Print' ';Print' ';Print' ';Print' ';Print' ';}Sub g_bott {Print'
File Upload Result)
SourceFile:DestFile:Upload
'. $ Xfile .''. $ Writed. $ strNetFname .'OK!
';
}
----------------------------------------------------------------------
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]

Bytes. Below we use two methods to achieve this function: 1. use PHP to save...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.