fread() and inline PDF display question 
Author Message
 fread() and inline PDF display question

Hi all,

I'm using PHP 4.2.3 and Apache 1.3 on Linux.  I'm trying to create a
PHP program which will fetch a PDF file from outside the webserver's
document root filesystem and display it to the user inline in the
browser.  My program so far looks like this:

<?php
  $file = "/var/docs/test.pdf";

  header("Cache-control: private");
  header("Content-Type: application/octet-stream");
  header("Content-Length: ".filesize($file));
  header("Content-Disposition: inline; filename=$file");

  $fd = fopen($file, "r");
  while(!feof($fd)) {
    echo fread($fd, 4096);
  }
  fclose ($fd);
?>

It almost works, but not quite.  When I load the page (pdftest.php),
the browser pops up a window asking if I want to open the file or save
it.  On the other hand, if I move the PDF file into the webserver
document root directory and link to it directly, it opens with Acrobat
in the browser immediately, which is the behavior I'm looking for, but
I don't want to store my PDF files in the webserver filesystem, for
various reasons.

Is there any combination of headers that will make this program do
what I want?

Thanks,

Steve



Mon, 30 May 2005 13:16:59 GMT  
 fread() and inline PDF display question

Quote:

> Hi all,

> I'm using PHP 4.2.3 and Apache 1.3 on Linux.  I'm trying to create a
> PHP program which will fetch a PDF file from outside the webserver's
> document root filesystem and display it to the user inline in the
> browser.  My program so far looks like this:

><?php
>   $file = "/var/docs/test.pdf";

>   header("Cache-control: private");
>   header("Content-Type: application/octet-stream");

change the above line to

header('Content-Type: application/pdf');

Quote:
>   header("Content-Length: ".filesize($file));
>   header("Content-Disposition: inline; filename=$file");

You may want to remove Content-Disposition, but I am not
sure ...

--
regards,
reggie.



Mon, 30 May 2005 14:00:52 GMT  
 fread() and inline PDF display question

Quote:


>>Hi all,

>>I'm using PHP 4.2.3 and Apache 1.3 on Linux.  I'm trying to create a
>>PHP program which will fetch a PDF file from outside the webserver's
>>document root filesystem and display it to the user inline in the
>>browser.  My program so far looks like this:

>><?php
>>  $file = "/var/docs/test.pdf";

>>  header("Cache-control: private");
>>  header("Content-Type: application/octet-stream");

> change the above line to

> header('Content-Type: application/pdf');

>>  header("Content-Length: ".filesize($file));
>>  header("Content-Disposition: inline; filename=$file");

> You may want to remove Content-Disposition, but I am not
> sure ...

These both sound like good suggestions to me. My general answer to this
question is to power up some packet capture software. I typically pick
ethereal for the job.

Once you capture both a working and non-working request/response pair,
it's usually pretty easy to "Follow TCP Stream" and see what's different.
--
Don Faulkner, KB5WPM        |
  This space                 | "All that is gold does not glitter."
  unintentionally left blank | "Not all those who wander are lost."
                             |                    -- J.R.R. Tolkien



Mon, 30 May 2005 16:22:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problemi con la funzione fread() - Problems with fread() function

2. Fread/Fwrite Questions

3. VisualWave: display a PDF file

4. looking for parts that display PDF docs

5. Displaying pdf-files using ocx

6. displaying PDF using TK

7. Can python have lib to display PDF ?

8. Search some String in PDF with PDF.OCX

9. Appendix.pdf - Appendix.pdf (0/6)

10. extract info from pdf doc,PDF to XML, HTML

11. CL-PDF the Common Lisp PDF Library 0.2

12. CL-PDF: need beta testers for cl-pdf 1.0

 

 
Powered by phpBB® Forum Software