Php – Can’t download file in IE7 but there isn’t any issue in Firefox, Chrome, etc..


I have an script that receives an encrypted url and from that generates a download, the most critic par of the script is this:

$MimeType = new MimeType();
$mimetype = $MimeType->getType($filename);
$basename = basename($filename);
header("Content-type: $mimetype");
header("Content-Disposition: attachment; filename=\"$basename\"");
header('Content-Length: '. filesize($filename));
if ( @readfile($filename)===false ) {
  header("HTTP/1.0 500 Internal Server Error");

Downloads works as charm in any Browser except IE, I have seen problems related to 'no-cache' headers but I don't send anything like that, they talk about utf-8 characters, but there is not any utf-8 characters(and the $filename has not any utf-8 characteres neither).

Best Solution

I solved it by sending the headers

header('Pragma: public');
header('Cache-Control: max-age=0');

I didn't knew that session_start() send headers by it's own.

I found the answer in the comments section of: Error: Internet Explorer Cannot Download FileName from WebServer

Related Question