分类分类
更新时间:2026-05-10 18:29:12作者:qazwsxzxc
文章介绍了用php实现多文件上传和下载的实现方法,希望可以帮助到有所需求的朋友!
核心思路:
header("content-type:application/octet-stream");
header("content-disposition:attachment;filename={$imgfile}");
header("content-length:{$imgsize}");
readfile($path);
index_uploads.php文件代码:
<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[]">
<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>
</html>
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>";
}
}
listdir.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><img src='$path'></td>";
echo "<td><a href='download.php?imgfile=$file'>Download</a></td>";
echo "</tr>";
}
}
}
}
echo "<h2>图片下载|<a href='index_uploads.php'>图片上传</a></h2>";
echo "<table width='700px' border='1px'>";
listdir($dirname);
echo "</table>";
download.php文件代码:
<?php
$imgfile = $_GET['imgfile'];
$path = '.https://file.a5xiazai.com/uploads/files/'.$imgfile;
$imgsize = filesize($path);
header("content-type:application/octet-stream");
header("content-disposition:attachment;filename={$imgfile}");
header("content-length:{$imgsize}");
readfile($path);
相关
卢希达起源0.1折版角色扮演1.16G2026-05-10
下载七柚剧场App影音播放61.9 MBv1.1.12026-05-10
下载凯越机车App生活服务285.15 MBv1.1.32026-05-10
下载美团出行司机端学习办公124.5 MBv2.16.12026-05-10
下载雅马哈摩托车App生活服务60.37 MBv3.8.02026-05-10
下载酷我音乐车载极简版影音播放57.26 MBv1.0.4.212026-05-10
下载快捷记账App实用工具20.88 MBv4.11.02026-05-10
下载塔吉多App手游辅助99.48 MBv1.2.22026-05-10
下载全集短剧免费最新手机版影音播放85.4 MBv1.1.72026-05-10
下载啦兔兔(直播平台)趣味娱乐136.9 MBv8.1.02026-05-10
下载莎莎隐私播放器(私人视频播放器)影音播放94.6 MBv1.3.02026-05-10
下载JPlayer视频播放器(多功能播放器)影音播放111.5 MBv3.6.32026-05-10
下载









