Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > Finally, PDF Header for PDF stuffs that work....
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 2nd July 19:02
scott
External User
 
Posts: 1
Default Finally, PDF Header for PDF stuffs that work....



Finally got some PHP header to force IE to display the PDF document right
from the file from the server. Due to most of IE bugs, this script will
help. It can be either getting a file from the webserver as this script is
or you can change the PHP header to use the attachment instead.

--snip--
<?
$filename=$_REQUEST['PDF_FileName'];
$filepath=$_REQUEST['PDF_FilePath'];

$filesize=filesize($filepath);

header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Content-Type: application/pdf");
header("Content-Length: ".$filesize);
header("Content-Disposition: inline; filename=$filename");
header("Content-Transfer-Encoding: binary");

//Can't use readfile() due to poor controlling of the file download.
//(IE have this problems)...
//readfile($filepath);

//use fopen() instead of readfile...
$fp = fopen($filepath, 'rb');
$pdf_buffer = fread($fp, $filesize);
fclose ($fp);

print $pdf_buffer;

//Required, to keep IE from running into problems
//when opening the file while downloading or downloading...
//(IE been acting strange...)
exit();
?>
--snip--
  Reply With Quote


 


2 2nd July 19:03
php-general
External User
 
Posts: 1
Default Finally, PDF Header for PDF stuffs that work....



readfile has no effect on how IE handles downloads.


Loading the whole file in memory and not doing anything with it
before sending it to the client doesn't make much sense.


This also doesn't effect IE.


Curt
--
"My PHP key is worn out"

PHP List stats since 1997:
http://zirzow.dyndns.org/html/mlists/
  Reply With Quote


 


3 2nd July 19:04
php-general
External User
 
Posts: 1
Default Finally, PDF Header for PDF stuffs that work....


Correct, readfile() doesn't load the whole file into memory.

Imagine if readfile did read the whole thing into memory. and you
have a script was sending 100MB files to the users and then 10 people
happend to come across your site at the same time. your system will
require, at minimum, 1000MB's of memory to send the files. And cross your
fingers the site doesn't get posted to a BBs.


Curt
--
"My PHP key is worn out"

PHP List stats since 1997:
http://zirzow.dyndns.org/html/mlists/
  Reply With Quote
4 3rd July 08:28
scott
External User
 
Posts: 1
Default Finally, PDF Header for PDF stuffs that work....


IE just don't work depending on some of the IE's version because of the IE's
countless bugs. So, a different method of controlling the data output to
the browser is needed. That's when I use the fopen() stuffs and it solve
the problem. It is evident by reduced customer's calling tech support
(us)... Questions about IE problem is something you would have to ask M$ on
why it is using hte faulty IE.

Scott F.
  Reply With Quote
5 3rd July 08:29
john
External User
 
Posts: 1
Default Finally, PDF Header for PDF stuffs that work....


OK, here's a different problem.

If I call a pdf file directly, the Acrobat plugin begins to display the
file almost immediately. Here is the reponse header for calling the file
directly:

HTTP/1.1 200 OK
Date: Thu, 16 Oct 2003 20:41:28 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12
OpenSSL/0.9.6b PHP/4.3.3 mod_perl/1.26
X-Meta-MSSmartTagsPreventParsing: TRUE
X-MSSmartTagsPreventParsing: TRUE
Last-Modified: Thu, 16 Oct 2003 17:08:17 GMT
ETag: "94174-341fcb-3f8ed081"
Accept-Ranges: bytes
Content-Length: 3416011
Connection: close
Content-Type: application/pdf

the pipe before anything is displayed. The mystery for me is that the
headers--the important ones anyway--look exactly the same. Dig:

HTTP/1.1 200 OK
Date: Thu, 16 Oct 2003 20:44:45 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12
OpenSSL/0.9.6b PHP/4.3.3 mod_perl/1.26
X-Meta-MSSmartTagsPreventParsing: TRUE
X-MSSmartTagsPreventParsing: TRUE
X-Powered-By: PHP/4.3.3
X-Accelerated-By: PHPA/1.3.3r2
Accept-Ranges: bytes
Content-Length: 3416011
Connection: close
Content-Type: application/pdf

Here's what's serving the file:

header("Content-Type: application/pdf");
header("Accept-Ranges: bytes");
header("Content-Length: ".filesize($thefile));
readfile($thefile);

Can anybody tell me why the browser is waiting for the entire file
before it's displayed(using php)? I don't think the average user will
have the patience to stare at a blank browser waiting for the file.

Thanks!
  Reply With Quote
6 3rd July 08:29
php-general
External User
 
Posts: 1
Default Finally, PDF Header for PDF stuffs that work....


This is a pdf issue I believe. There is an option in the PDF called
'Fast Web View', if this is set adobe doesn't need to read the
whole thing before starting to view.

Check the pdf's 'Document properties' and You'll see if the option
is set or not. If not, resave the document enabling that option.

Acrobat 5 has a nice little batch thing to convert serveral
docuements into this mode.

HTH,

Curt
--
"My PHP key is worn out"

PHP List stats since 1997:
http://zirzow.dyndns.org/html/mlists/
  Reply With Quote
7 3rd July 08:29
john
External User
 
Posts: 1
Default Finally, PDF Header for PDF stuffs that work....


I appreciate that advice. And Fast Web View is disabled. But I still
don't understand why calling the file directly gives immediate output,
but if I generate the headers and readfile() the file to the browser
(same exact file) it waits to get the whole file.
  Reply With Quote
8 3rd July 08:30
php-general
External User
 
Posts: 1
Default Finally, PDF Header for PDF stuffs that work....


I forgot to also mention this:

I'd put a high wager that the pdf has been cached and is being
loaded from the cache instead.

Notice no Etag, last-modified. There is no way IE or any browser
can cache this document, it is going to request it all the time.


Curt
--
"My PHP key is worn out"

PHP List stats since 1997:
http://zirzow.dyndns.org/html/mlists/
  Reply With Quote
Reply


Thread Tools
Display Modes




666