Internet Explorer, php, Web Development

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');

1 thought on “PHP – Download File with IE Support”

Leave a reply

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