Too Cool for Internet Explorer

How to force file downloading with htaccess   July 1st, 2009

Nearly every browser will show image oder video files you want to provide for download in the browser itself instead of opening a download dialog.

Most of the websites suggest to use this code in your .htaccess:

<FilesMatch "\.(jpg|zip|avi)$" >
	ForceType application/octet-stream
</FilesMatch>

But this is not enough! Even when the MIME-Type is set to “octet-stream”, some browsers will still open the files their selfs because they have detected the .jpg or .avi file extension.

The solution to this is to add the following header:

<FilesMatch "\.(jpg|zip|avi)$" >
	ForceType application/octet-stream
	Header add Content-Disposition "attachment"
</FilesMatch>

With this header every browser i tested opened a download dialog, regardless of which file extension is present.

Tags: , , , , ,
This entry was posted on Wednesday, July 1st, 2009 at 19:34 and is filed under Programming. You can follow any responses to this entry through the RSS 2.0 feed.You can leave a response, or trackback from your own site.

4 Responses

October 5th, 2011 at 01:19
Mamun Says:

I used the below one for force PDF download. I am using Apache 2.2.17. But I got an internal server error (500).

ForceType application/octet-stream
Header add Content-Disposition “attachment”

Can anyone help me regarding this.

November 23rd, 2011 at 13:06
admin Says:

I am afraid i can’t help you with this, it works fine for me. Is there maybe an error in the FilesMatch directive?

January 13th, 2012 at 19:04
Yasin Says:

Hi,

it didn’t work first time i tried, then i cleared the browser cache and it worked. This is a very good solution.
It would be interesting, if it works with IE. Im using FF on Mac OSX

Thanks for sharing this.

January 14th, 2012 at 06:16
admin Says:

yes, it works with IE. i used it in a big portal page without errors.

Leave a Reply