php代码实现简单图片下载

连接代码:
<a href="test.php?url=test/images/image_01.jpg">图片下载</a>

test.php文件代码:
$filename = $_GET['url'];//图片地址,可以绝对地址也可以相对地址
header("Content-Type: application/force-download");
header('Content-Disposition: attachment; filename="'.$filename.'"'); //第二、三行代码告诉浏览器强制下载文件
$img = file_get_contents($filename); 
echo $img;
 
原文地址:https://www.cnblogs.com/YTzZ/p/4311313.html