强制浏览器下载带有Javascript窗口的图像。打开?
2022-08-30 16:00:46
有没有办法在单击图像后将其下载(无需右键单击将图像另存为)?
我正在使用一个小的Javascript函数来调用下载页面:
<a href="#"
onclick="window.open('download.php?file=test.jpg', 'download', 'status=0');"
>Click to download</a>
在下载.php页面中,我有这样的东西:
$file = $_GET['file'];
header('Content-Description: File Transfer');
header("Content-type: image/jpg");
header("Content-disposition: attachment; filename= ".$file."");
readfile($file);
但它不起作用。我做错了什么?
提前致谢!