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);    

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.