PHP Multi-File Upload download sample code
index_uploads.php
<?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
<?php Header ("Content-type:text/html;charset=utf-8"); $dirname = "Uploads/files"; function Listdir ($dirname) { $ds = Opendir ($dirname); while ($file = Readdir ($ds)) { $path = $dirname. ' /'. $file; if ($file! = '. ' && $file! = ' ... ') { if (Is_dir ($path)) { listdir ($path); } else { echo "<tr>"; echo "<td></td>"; echo "<td><a href= ' download.php?imgfile= $file ' >Download</a></td>"; echo "</tr>"; }}} echo "
listdir.php
<?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);d ownload.php
download.php
Core Downloads:
Header ("Content-type:application/octet-stream"); Header ("Content-disposition:attachment;filename={$imgfile}"); Header ("content-length:{$imgsize}"); ReadFile ($path);