我一直在试图迫使图像使用PHP头下载,但也出现了许多问题。
I have been trying to force images to download using PHP Headers but there have been multiple problems.
所以,相反,我该如何使用的.htaccess
所以,当我联系到一个图像,如:
So, instead, how can I use .htaccess
so that when I link to an image like:
<a href="wallpapers/image.jpg">Download</a>
而不是打开的浏览器,文件
...,文件被实际下载并保存到用户的计算机。
...instead of opening that file in browser, the file is actually downloaded and saved to the user's computer.
我已经使用的.htaccess在我的项目重写URL是否会影响什么。
I am already using .htaccess in my project to rewrite URLs if that affects anything.
将这个到你的.htaccess
Put this into your .htaccess
<FilesMatch ".(?i:jpg|gif|png)$">
Header set Content-Disposition attachment
</FilesMatch>