如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
html
1 2 3 4 5 6 |
<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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?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); |