Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");
  loadErrorPage('500');
}

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).

like image 968
levhita Avatar asked Sep 22 '08 20:09

levhita


People also ask

Why is Firefox blocking my Downloads?

Firefox includes a download protection feature to protect you from malicious or potentially harmful file downloads. If Firefox has blocked an unsafe download, you will see a warning message about the file in the Downloads panel, along with options for handling the pending download.

Why are my browser files not downloading?

This error means that your computer's security settings blocked the file. Learn more about blocked downloads. On Windows: Windows Attachment Manager could have removed the file you tried to download. To see what files you can download or why your file was blocked, check your Windows internet security settings.

Why do Downloads keep failing?

Issues with Internet connectivity and the stability of the connection can cause downloads to fail, especially if the Internet connection is interrupted. When an Internet connection is unstable, it may disconnect and reconnect intermittently.


1 Answers

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

like image 160
levhita Avatar answered Sep 27 '22 20:09

levhita