Copy Code code as follows:
<meta charset= "Utf-8" >
<title>index_uploads</title>
<body>
<form action= "uploads.php" method= "post" enctype= "Multipart/form-data" >
<input type= "File" Name= "file[]" >
<br>
<input type= "File" Name= "file[]" >
<br>
<input type= "File" Name= "file[]" >
<br>
<input type= "File" Name= "file[]" >
<br>
<input type= "File" Name= "file[]" >
<br>
<input type= "Submit" value= "uploads" >
</form>
</body>
index_uploads.php
Copy Code 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
Copy Code code as follows:
<?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 "echo "<table width= ' 700px ' border= ' 1px ' >";
Listdir ($dirname);
echo "</table>";
listdir.php
Copy Code code 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 Downloads:
Copy Code code as follows:
Header ("Content-type:application/octet-stream");
Header ("content-disposition:attachment;filename={$imgfile}");
Header ("content-length:{$imgsize}");
ReadFile ($path);