Sometime you don’t want to give your site visitors the option to open a file in their web browser. This could be a Microsoft Office document, or even a giant jpg or png image. When you want to force download a certain file type, simple add something like this to an .htaccess file in the directory that the file(s) are located in:
<Files *.xls> ForceType application/octet-stream Header set Content-Disposition attachment </Files> <Files *.eps> ForceType application/octet-stream Header set Content-Disposition attachment </Files>
This particular directive forces downloads all .xls and .eps files (the * means match any file name, followed by the extension of the file) in the same directory, as well as any sub-directories, and ensures that the browser will not try to open the file.
In general, I like to avoid putting such things in my root .htacess file, preferring to create a “downloads” directory of some sort, and just adding the above lines as needed.
Broke our server with a 500 error.
Removing the Header set line stopped it.
For those Expression Engine users out there, this did not work for me until I moved the rules into the .htaccess file in the root.
Placing an .htaccess file in the folder that contained the images was not effective.
You need to:
LoadModule headers_module modules/mod_headers.so
ForceType application/octet-stream
Header set Content-Disposition attachment
Works fine.