Home >Backend Development >PHP Tutorial >HP pavilion dv1000 allows you to upload 1000 files at the same time (2)

HP pavilion dv1000 allows you to upload 1000 files at the same time (2)

WBOY
WBOYOriginal
2016-07-29 08:34:531053browse

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 the path)
All that's left is to write a loop to write the files to the server one after another. 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 stored in the variable $file0, and the file name is stored in $file0_name. 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" ]
                                                                                                       $i;
              $ffnnname=$ffnn."_name";                                                                                                                                                                     
        fup ($$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;
&g_body;
}
&g_bott; <<<<<<<<<sub upfile
{
$maxdata = 512000;
# $written = '../www/test/tmp /';
  $strRFname=reverse $xfile;
  $intIndex=index($strRFname,'');
  $strNetFname=substr($strRFname,0,$intIndex);
    $strNetFname=scalar reverse $strNetFname;
   
if((stat $xfile)[7]>$maxdata){
                                                                                                                                                                                             . ; 411 411 Size Not Allowed

You got big problem. Try again.

n ";
" exit 0;
" }
"
" binmode $xfile;
use File::Copy;
copy($xfile,$written.$strNetFname);
}
sub g_head{
  print '';
 print '< /tr>';
print '';
print ' ';
print ' print ' ';
print ''; '';
print ' ';
}
sub g_bott{
  print '
File upload result (Upload Result)
SourceFile:Upload
';
}
------------------------ --------------------------------------------------
If it’s good For suggestions, please email: gearsoft@netease.com
【The copyright of this article is jointly owned by the author gearsoft and OOSO.com. If you need to reprint, please indicate the author and source】

The above introduces the hp pavilion dv1000 that allows you to upload 1000 files at the same time (2), including the content of the hp pavilion dv1000. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement:
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