Force Files to Download Instead of Opening

November 5th, 2007

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

8 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

  4. Jon Says:

    Great! A simple answer to a common question.

    Thanks

  5. Nilpo Says:

    Thanks for taking the time to comment. I’m glad you found this useful.

  6. Harsh Says:

    Hi.. I don’t know your name,

    but that you very much for your short description about how to display file instead of executing that and how to download instead of opening. That helps me a lot…

    thank you very much..
    Harsh

  7. Tim Says:

    Good afternoon. I’am french speaker. You’re post interest me a lot. I think frensh are according with you. Sorry for languge error ;-)

  8. Nilpo Says:

    Merci, Tim. J’apprécie tes mots aimables. ;)

Leave a Reply

.htaccess Apache article articles by Nilpo ASP ASP Free automation clipboard desktop Dev Shed docx drive Internet Explorer Microsoft PHP registry remove script scripting text tutorial tweak tweets Twitter UAC updates User Account Control VBS VBScript vista volume Windows Windows 7 Windows 2000 Windows Guru Windows Script Windows Script Host Windows Scripting Windows Vista Windows XP Word WScript wscript.exe WSH XP