Code Snippets Gallery
Force Files to Download (Not Open in Browser)
AddType application/octet-stream .csv
AddType application/octet-stream .xls
AddType application/octet-stream .doc
AddType application/octet-stream .avi
AddType application/octet-stream .mpg
AddType application/octet-stream .mov
AddType application/octet-stream .pdf
make sure to put this poop in .htaccess
Wow, I’ve been trying to figure out how to do this for a very, very (very) long time! Is there any way you can make it specific, for example, if I click “link 1″, I can view the file in browser, but if I click “link 2″, the “AddType” function is applied, and I am forced to download?
Thanks in advance, and sweet snippet!
It’s not an ideal solution to your problem, but you could have a php wrapper for download links that simply takes an argument that is the filename and then reads the file (assuming local files) and before outputting the file to the user you send headers with the filetype. see http://www.php.net/manual/en/function.header.php for more information about php and headers.
This is a great one. I had forgotten about it before but I’m glad I found it again!
Thanks
What abouton a windows server? I can’t get the .htaccess for to work – is this only for apache users?
Correct. Anything .htaccess is only Apache.
Hi!, that was awesome, i just found this tutor on google,
thanks!, and now its possible to not use header function.
I m using apache2triad and in this there is no .htaccess named file so now what todo?
I like it short ;)
AddType application/octet-stream .doc .mov .avi .pdf .xls .mp4
thanks a lot!!!