Click to See Complete Forum and Search --> : Problems serving PDFs on Internet Explorer


GaryS
06-20-2006, 12:47 PM
I'm serving file downloads using header information. I've used the approach a number of times on a number of different websites... but have just run into a problem on one website with IE for .pdf files.

I'm aware that the IE handles downloads in two requests, so that "don't cache" can result in "file not found."

Don't think I have a caching issue in this case; wondering if there's anything else that could cause IE to report "file not found" ?

(More info: clicking the download link causes the browser to prompt the user to Open/Save/Cancel. The saving option works on all browsers.)

(Even more info - here's the header info in response to a "click" on the link:

http://test.website.co.uk/download/30

GET /download/30 HTTP/1.1
Host: test.website.co.uk
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://test.website.co.uk/resources/support
Cookie: __utma=98650317.1097540879.1138871938.1150793718.1150801101.236; __utmz=261328520.1145637548.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utma=261328520.335742099.1145637548.1147282738.1147417751.16; __utmz=98650317.1150793718.235.74.utmccn=(referral)|utmcsr=test.website.co.uk|utmcct=/|utmcmd=referral; __utmc=98650317

HTTP/1.x 200 OK
Date: Tue, 20 Jun 2006 18:14:52 GMT
Server: Apache/1.3.33 (Unix) (Red-Hat/Linux) PHP/4.3.10 mod_ssl/2.8.19 OpenSSL/0.9.7a FrontPage/4.0.4.3
X-Powered-By: PHP/4.3.10
content-disposition: attachment; filename="testfile.pdf"
Content-Length: 133779
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: application/pdf
----------------------------------------------------------

dc2000
06-20-2006, 10:58 PM
I was always using the following function to send files back to user for saving:
function send_file($path, $fname)
{
//Send file as attachment
//RETURN: = true if done; false if error
session_write_close();
ob_end_clean();
if(!is_file($path) || connection_status() != 0)
return false;

//to prevent long file from getting cut off
set_time_limit(0);

$name = basename($fname);

header("Cache-Control: ");
header("Pragma: ");
header("Content-Type: application/octet-stream");
header("Content-Length: ".(string)(filesize($path)));
header('Content-Disposition: attachment; filename="'.$name.'"');
header("Content-Transfer-Encoding: binary\n");

if($file = fopen($path, 'rb'))
{
while((!feof($file)) && (connection_status()==0))
{
print(fread($file, 1024*8));
flush();
}
fclose($file);
}

return connection_status() == 0 && !connection_aborted();
}
It always works for me for any kind of file...

GaryS
06-21-2006, 01:05 AM
You may well have saved my life, dc2000! What you have there is a good bit more sophisticated than the function I've been using - and the cache-related stuff looks very promising. I'll have a play this morning and post back.

GaryS
06-21-2006, 03:39 AM
Works perfectly. A million thanks!