有没有一种方法,使得在单击图像时可以直接下载图像(而不用右键点击“另存为”)?
我正在使用一个小的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);
但它没有起作用。我做错了什么?
提前感谢!