如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
html
<a href="./1.php?name=1.jpg">1.jpg</a>
<a href="./1.php?name=2.jpg">2.jpg</a>
<a href="./1.php?name=3.jpg">3.jpg</a>
<a href="./1.php?name=1.png">1.png</a>
php
<?php
header("content-type:text/html;chatset=utf-8");
date_default_timezone_set("PRC");
$name = $_GET['name'];
$ext = pathinfo($name,PATHINFO_EXTENSION);
//限制类型
$type = array(
'jpg'=>'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif',
'txt' => 'text/plain',
'html' => 'text/html',
'php' => 'text/plain',
'zip' => 'application/zip',
);
//下载设定
header('Content-Type:'.$type[$ext]);
//文件名
header('Content-Disposition: attachment;filename="'.$name.'"');
header('Content-Cength:'.filesize('./img/'.$name));
//下载资源位置
readfile('./img'.$name);