user187580
user187580

Reputation: 2315

Internet explorer file download error while doing "readfile" - PHP

I have just moved a web application to a windows server and having some problems. One of it is - application stores list of names of files in a database table. when a files is requested for download it is sent to output by sending proper headers (depending upon mime type and then a readfile("document location/filename.extension");

it works fine in firefox but if I try to download in IE it throws

IE can not dowload this document from www.mysite.com .. IE was unable to open this Internet site. The requested file is either unavailable or cannot be found. Please try again later.

As it was working fine on previous server (non-windows), I tried to print document location and it read somewhat like C:/Apache/htdocs/FILENAME.ext and I guess this C:/ is causing problem in IE but not in firefox??

How do I get it working right in IE??

Thanks

UPDATE

I have got it working by adding some more headers among others .. I think first 2 are more important for IE or so (atleast working for me for now :)

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();

Upvotes: 2

Views: 4306

Answers (3)

StefBroox
StefBroox

Reputation: 11

It works :

if (strstr($_HTTP_USER_AGENT, "MSIE")) { 
    header("Pragma: public"); 
    header("Expires: 0"); 
    header("Cache-Control: doit-revalider, post-check = 0, pré-check = 0"); 
    header("Content-Type: application de téléchargement; name=\"$sFilename\""); 
    header("Content-Length: $iTaille"); 
    header("Content-Disposition: attachment; filename=\"$sFilename\""); 
    header("Content-Transfer-Encoding: binary"); 
} else { 
    header("Content-Type: application de téléchargement; name=\"$sFilename\""); 
    header("Content-Length: $iTaille"); 
    header("Content-Disposition: attachment; filename=\"$sFilename\""); 
} 

Upvotes: 1

symcbean
symcbean

Reputation: 48357

Is this by any chance over SSL? If so, there are a whole host of bugs in MSIE which could be affecting your app. Try setting a very short caching time.

If it works on Firefox using the the same server, then the problem unlikely to be anything to do with the path on the server. Although beware that (IME) IIS seems to tunnel authorization from MSIE clients (but not others) in some instances.

Upvotes: 0

Flatlin3
Flatlin3

Reputation: 1659

this question had already been answered here PHP: Force file download and IE, yet again

Upvotes: 0

Related Questions