本文介绍了强制浏览器使用Javascript window.open下载图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让图片一旦点击就可以下载(没有右键单击将图像另存为)?
Is there a way to make an image a download once you click on it (without right-click save image as)?
我正在使用一个小的Javascript函数来调用下载页面:
I'm using a small Javascript function to call the download page:
<a href="#"
onclick="window.open('download.php?file=test.jpg', 'download', 'status=0');"
>Click to download</a>
在download.php页面中我有类似的内容:
In the download.php page I have something like:
$file = $_GET['file'];
header('Content-Description: File Transfer');
header("Content-type: image/jpg");
header("Content-disposition: attachment; filename= ".$file."");
readfile($file);
但它不起作用。我做错了什么?
提前致谢!
But it doesn't work. What am I doing wrong?
Thanks in advance!
推荐答案
使用而不是 image / jpg :
这篇关于强制浏览器使用Javascript window.open下载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!