PHP multi-File upload download sample sharing

Source: Internet
Author: User
Tags file upload readfile

  This article mainly introduces php multiple file upload download sample, need friends can refer to the following

  Code as follows: <html> <head>     <meta charset= "Utf-8" >     <title>index_ Uploads</title> </head> <body>     <form action= "uploads.php" method= "POST" enctype= " Multipart/form-data ">         <input type=" file "name=" file["" >         & lt;br>         <input type= "file" Name= "file[]" >         <br> &nbsp ;       <input type= "file" Name= "file[]" >         <br>       & nbsp <input type= "File" Name= "file[]" >         <br>         <input type= "File" Name= "file[]" >         <br>       <input type= "Submit" value= "Uploads" >     </form> </body> </html>     index_uploads.php   code as follows: PHP     echo "<pre> ";     Print_r ($_files);     echo "</pre>";       $count = count ($_files[' file '] [' name ']);       for ($i = 0; $i < $count; $i + +) {        $tmpfile = $_files[' file '] [' Tmp_name ' [$i];         $filefix = Array_pop (Explode (".", $_files[' file '] [' name '] [$i]);         $dstfile = "uploads/files/". Time (). " _ ". Mt_rand ().". ". $filefix;           if (Move_uploaded_file ($tmpfile, $dstfile)) {            echo "<script>alert (' succeed! '); window.location.href= ' listdir.php ';</script> ';        } else {            echo <script>alert (' fail! '); window.location.href= ' index_uploads.php ';</script> ';        }     {      uploads.php     code: <?php     H Eader ("content-type:text/html;charset=utf-8 ");     $dirname = "Uploads/files";       function Listdir ($dirname) {        $ds = Opendir ($dirname);     &NBSP ;   while ($file = Readdir ($ds)) {            $path = $dirname. ' /'. $file;             if ($file!= '. ' && $file!= ' ... ') {                if (Is_dir ($path)) {            & nbsp       Listdir ($path);                } else {                & nbsp   echo "<tr>";                     echo "<td><img src= ' $path ' ></td>";                     echo "<td><a href= ' download.php?imgfile= $f Ile ' >Download</a></td> ';                     echo "</tr>";                            }            }      echo "<h2> picture download |<a href= ' index_uploads.php ' > image upload </a></ H2> ";     echo "<table width= ' 700px ' border= ' 1px ' >";     Listdir ($dirname);     echo "</table>";           listdir.php     code is as follows: <?php     $imgfile = $_get[' Imgfile '];     $path = './uploads/files/'. $imgfile;     $imgsize = FileSize ($path);       Header ("Content-type:application/octet-stream");     Header ("content-disposition:attachment;filename={$imgfile}");     Header ("content-length:{$imgsize}");     ReadFile ($path);   download.php       download.php   core download:     Code as follows: Header ("content-type:application/ OcTet-stream "); Header ("content-disposition:attachment;filename={$imgfile}"); Header ("content-length:{$imgsize}"); ReadFile ($path);    
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.