Forum Moderators: coopster

Message Too Old, No Replies

PDF downloads using readfile()

How to open in browser window?

         

dcrombie

3:53 pm on Feb 23, 2005 (gmt 0)



I'm using a PHP script and mod_rewrite to serve files:

The page address is of the form: [example.net...]

and the following headers are sent:

header("Content-Disposition: attachment; filename=\"$filename\""); 
header("Content-Length: $filesize");
header("Content-Type: $filetype");
readfile($file);
exit(0);

The problem (for one of our clients) is that this always forces a download prompt. I tried adding:

header("Cache-Control: public, no-cache");

but it had no effect.

Anyone?

Elijah

2:22 am on Feb 24, 2005 (gmt 0)

10+ Year Member



I would try either removing the "Content-Disposition" header completely or changing it from "attachment" to "inline" like this:
header("Content-Disposition: inline; filename=\"$filename\"");

I got the idea for removing the "Content-Disposition" header by using the Live HTTP headers extension for Firefox and loading up a PDF file from my website which displayed in the browser window. The server did not send a "Content-Disposition" header.

I got the idea for changing the "Content-Disposition" header from "attachment" to "inline" from RFC 2183.

Hope this helps,

Elijah

dcrombie

10:10 am on Feb 24, 2005 (gmt 0)



That seems to work - excellent!