5

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">Download</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.

Simon East
  • 55,742
  • 17
  • 139
  • 133
Moon
  • 19,518
  • 56
  • 138
  • 200
  • What were the problems with the PHP headers? – Evan Mulawski Nov 18 '10 at 19:00
  • I think this was answered here: http://stackoverflow.com/questions/1010636/force-link-to-mp3-file-to-download-save-as/1010663#1010663 – Gregg B Nov 18 '10 at 19:02
  • @Grillz: tried that already after googling.. not working... @Evan PHP was making images but not not displaying them... if you have cent percent error proof code then be my guest – Moon Nov 18 '10 at 19:10

1 Answers1

18

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.

That Brazilian Guy
  • 3,328
  • 5
  • 31
  • 49
Jan Thomä
  • 13,296
  • 6
  • 55
  • 83