levhita
levhita

Reputation: 2171

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

Upvotes: 5

Views: 6818

Answers (3)

Navin_S7Software
Navin_S7Software

Reputation:

Use this

In IE7 Browser go to internet option--> security--->custom level --->downloads then enabled autometic prompting for file download.

this will solve the problem.

hope this will help

Upvotes: 0

levhita
levhita

Reputation: 2171

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

Upvotes: 8

Grant Wagner
Grant Wagner

Reputation: 25931

This site has a problem similar to yours in IE6. To summarize:

session_start() by default sends a cache control header including "no-store". Internet Explorer takes this a bit too literally, but doesn't have appropriate error handling for the case, and as a result explodes cryptically when you attempt to save the output page to disk.

Before session_start(), add "session_cache_limiter('none');", or look up that function and tweak the limiter as appropriate (probably 'private' is closer to the mark).

I realize the code snippet you posted does not include a call to session_start();, but I figured I'd share this possible solution in case you do have a call to it and just didn't show us.

Upvotes: 3

Related Questions