开发者

Force a file or image to download using .htaccess

开发者 https://www.devze.com 2023-01-25 15:24 出处:网络
I have been trying to force images to download using PHP Headers but there have been multiple problems.

I have been trying to force images to download using PHP Headers but there have been multiple problems.

So, instead, how can I use .htaccess so that when I link to an image like:

<a href="wallpapers/image.jpg">D开发者_开发问答ownload</a>

...instead of opening that file in browser, the file is actually downloaded and saved to the user's computer.

I am already using .htaccess in my project to rewrite URLs if that affects anything.


Put this into your .htaccess

<FilesMatch "\.(?i:jpg|gif|png)$">
  Header set Content-Disposition attachment
</FilesMatch>

Make sure you have mod_headers installed and enabled.

0

精彩评论

暂无评论...
验证码 换一张
取 消