download.php下载代码
1 <?php 2 //获取要下载的文件名 3 $filename = $_GET['filename']; 4 //设置头信息 5 header('Content-Disposition:attachment;filename=' . basename($filename)); 6 header('Content-Length:' . filesize($filename)); 7 //读取文件并写入到输出缓冲 8 readfile($filename);
Html调用
<a href="download.php?filename=./files/test1.jpg">下载图片</a>