有没有办法让图像在单击后立即下载(无需右键单击将图像另存为)?
我正在使用一个小的 Javascript 函数来调用下载页面:
<a href="#"
onclick="window.open('download.php?file=test.jpg', 'download', 'status=0');"
>Click to download</a>
在 download.php 页面中我有类似的内容:
$file = $_GET['file'];
header('Content-Description: File Transfer');
header("Content-type: image/jpg");
header("Content-disposition: attachment; filename= ".$file."");
readfile($file);
但这不起作用。我究竟做错了什么?
提前致谢!
Use 应用程序/八位字节流代替图片/jpg:
如果在具有 application/octet-stream 内容类型的响应中使用 [Content-Disposition] 标头,则隐含的建议是用户代理不应显示响应,而应直接输入“将响应另存为...”对话。
— RFC 2616 – 19.5.1 内容处置
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)