Allow you to upload 1000 files at the same time (ii) _php Foundation

Source: Internet
Author: User
Tags file upload
The file submission page has been generated and the following task is clear: Save the submitted file contents to the server.

Here's a couple of ways to do this:

1. Use PHP to Save:
We first define a file Save function fup () it has two parameters:
$filename: File contents
$fname: File name (including path)
All that's left is to write a loop to write the file to the server sequentially. Here's a quick explanation:
PHP for upload file processing is like this: if the submitted file box I for FILE0, then the file submitted to PHP saved 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 down the content submitted by the submission 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 "<br>";

Fup ($ $FFNN, $ $ffpath. $ $ffnnname); //".. /www/test/tmp/"
}
?>
----------------------------------------------------------------------

2. Use PERL to Save:
They implement exactly the same principle, not to say much, see 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".
"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;

#<<<<<<<<<<<<<<<<<<<<< The following is a custom process <<<< <<<<<<<<<<<<<<<<<<<<<

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".
"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> File Upload results (Upload result) </td></tr> ';
print ' <tr align=center> ';
print ' <td>SourceFile:</td> ';
print ' <td>DestFile:</td> ';
print ' <td>Upload</td> ';
print ' </tr> ';
}

Sub g_body{
print ' <tr> ';
print ' <td> '. $xfile. ' </td> ';
print ' <td> ' $writed. $strNetFname. ' </td> ';
print ' <td>OK!</td> ';
print ' </tr> ';
}

Sub g_bott{
print ' </table> ';
}
----------------------------------------------------------------------
If you have good suggestions, please email:gearsoft@netease.com.

"This article copyright belongs to the author Gearsoft and Osso Nets jointly owned, if need to reprint, please specify the author and source"

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.