PHP – Download File with IE Support

Consider this simple file download in PHP. This is expected to work in Firefox, Chrome and Safari.

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=my_file.csv');

It works great in Firefox! However, it does not work in IE6 and IE7. I haven’t tested IE8 since I don’t have one.

The workaround is to add additional headers like this:

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=my_file.csv');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
This entry was posted in Internet Explorer, php, Web Development and tagged , , , , , . Bookmark the permalink.

Related Posts

One Response to PHP – Download File with IE Support

  1. Yogesh Kale says:

    Great Work…Very Very helpful information

Leave a Reply

Your email address will not be published. Required fields are marked *