有没有办法在单击后下载图像(无需右键单击将图像另存为)?
我正在使用一个小的 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);
但它不起作用。我究竟做错了什么?
提前致谢!