Re: displaying a pdf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 30/05/2011, at 9:02 AM, Jim Giner wrote:

> Perhaps someone can tell me what I'm doing wrong.  I did some ( a lot) 
> looking around for hints on this and here is what I have compiled.  It 
> doesn't work - just goes to a white, blank page and sits.  I don't know if I 
> need all the html parts or even if I have placed my php in the right areas.
> 
> BTW - all I want to do is use a menu option to take me to a page that shows 
> the pdf.  My menu (a js thing) won't let me use an <a> element, so I'm 
> trying to just build a php page that I can go to and display the doc 
> automacitcally without the user having to click on something..
> 
> [code begins]
> <?php
> session_start();
> $root = $_SERVER['DOCUMENT_ROOT'];
> $pdfname='/pdfs/myfile.pdf';
> $length = filesize($pdfname);
> //
> header("Content-type: application/pdf");
> header("Content-Disposition: inline; filename=".$pdfname);
> header("Content-Length: ".$length);
> //
> ?>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
> "http://www.w3.org/TR/html4/loose.dtd";>
> <html>
> <head>
> </head>
> <body>
> <?
> readfile=$pdfname;
> ?>
> </body>
> </html>
> [code ends]
> 
> Thanks in advance! 

You don't want the HTML, as it's not part of the PDF. The first example on http://php.net/header even shows what you're trying to achieve.

<?php
session_start();
$root = $_SERVER['DOCUMENT_ROOT'];
$pdfname='/pdfs/myfile.pdf';
$length = filesize($pdfname);
//
header("Content-type: application/pdf");
header('Content-Disposition: inline; filename='.basename($pdfname).'"');
header("Content-Length: ".$length);
//
readfile($pdfname);

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux