Force Files to Download Instead of Opening

November 5th, 2007
1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 5 out of 5)
Loading ... Loading ...

Have ever wished that you could force a file to download instead of opening in a browser? Some common files like MP3s and PDFs will open in your reader’s browser if the proper parent plugin is installed. Sometimes you want to force them to download the file without having to right-click and save it.

This action can be achieved very easily in Apache by modifying the .htaccess file. You can set it at your domain root to affect your entire site, or you can set it in subdirectories to only affect parts of your site.

All you need to know is your file extension(s). Then add an octet-stream mime type for each. So you might add the following to your .htaccess file.

AddType application/octet-stream .avi 
AddType application/octet-stream .mpg
AddType application/octet-stream .mov
AddType application/octet-stream .pdf

The above example would force a download message and prevent any AVI, MPG, MOV, or PDF file from opening in a browser.

Please use the trackback link when linking to this post.

Related Posts:

Add to Technorati Favorites

3 Responses to “Force Files to Download Instead of Opening”

  1. Rob Says:

    Hey,
    Thanks for the tip! I have been trying to get this result for a few hours now. I have set up HTML email signatures for everyone in my office with a link to download our Vcards, but the vcfs keft displaying in the browser. Thank you very much!

  2. Nilpo Says:

    No problem at all. I’m glad you found this tip helpful!

  3. Cristiano Says:

    I need running this at IE6 , but not working.
    not force download in ie6.

    att,
    Cristiano

Leave a Reply