Let you upload 1000 files simultaneously (ii) _php tutorial

Source: Internet
Author: User
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 ' '; print ' '; print ' '; print ' '; print ' '; print ' '; } Sub g_body{print ' '; print ' '; print ' '; print ' '; print ' '; } Sub g_bott{print '
File upload results (Upload result)
SourceFile:DestFile:Upload
'. $xfile. ''. $writed. $strNetFname. 'Ok!
';
}
----------------------------------------------------------------------
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 ...

  • Related Article

    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.