强制文件或图像使用的.htaccess下载 [英] Force a file or image to download using .htaccess
本文介绍了强制文件或图像使用的.htaccess下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在试图迫使图像使用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>
这篇关于强制文件或图像使用的.htaccess下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文