views:

2915

answers:

4

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

+3  A: 

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.

Grant Wagner
Yes there is a sessions_start() above all, i just post that code because is a very long code.
levhita
+4  A: 

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

levhita
A: 

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

You can't really ask all your users to do the same :)
Luk
A: 

Thanks you, you saved my day

alex