Home > Backend Development > PHP Tutorial > Let you upload 1000 files at the same time (2)_PHP tutorial

Let you upload 1000 files at the same time (2)_PHP tutorial

WBOY
Release: 2016-07-21 16:01:33
Original
718 people have browsed it

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" .
"Your web browser cannot upload files. Sorry.";
exit 0;
}


$cntfile=param('cnt');
print header;
print start_html;
#print "Receiving Please wait....";

&g_head;

#$written = '../www/test/tmp/';

for ($i=0;$i<$cntfile;$i++ ){
$paramfile = 'file'.$i;
$parampath='path'.$i;

$written=param($parampath);

&upfile ;
                                           ;<<<<<<<
sub upfile
{
$maxdata = 512000;
# $written = ' ../www/test/tmp/';


$strRFname=reverse $xfile;
$intIndex=index($strRFname,''); $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 Allowed< /head>

You got big problem. Try again.

n";
 
binmode $xfile;
use File::Copy;
copy($xfile,$written.$strNetFname);
}

sub g_head{
    print '';
    print '';
    print '';
    print '    ';
    print '    ';
    print '    ';
    print '';
}

sub g_body{
    print '';
    print '    ';
    print '    ';
    print '    ';
    print '';
}

sub g_bott{
    print '
文件上传结果(Upload Result)
SourceFile:DestFile:Upload
'.$xfile .''.$writed.$strNetFname.'OK!
';
}
----------------------------------------------------------------------
如有好的建议请 Email: gearsoft@netease.com  

【本文版权归作者gearsoft与奥索网共同拥有,如需转载,请注明作者及出处】     

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/316779.htmlTechArticle文件提交页面既已生成,下面任务就很明确了:将提交的文件内容保存到服务器上。 下面我们用两种方法来实现这个功能: 1. 用 PHP 来保存...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template