Page 1 of 1

show pdf content in user browser

Posted: Sun Jun 06, 2004 11:55 pm
by maldar
Hi all
I have a problem and am confused
I have many pdf files in my website and desire to show content of each pdf file when user click on its link (such as this http://www.mywebsite.com/show.php?file1.pdf

I use this script for opening pdf files and tell user browser to show it(open adobe reader in browser):


Code: Select all

<?php 
header( "Content-type: application/pdf" ); 
header("Content-disposition: inline;"); 

$filename = $_GET&#1111;'filename']; 
$fp = fopen ( $filename, "r" ); 
$output = fread( $fp, filesize( $filename ) ); 
fclose ( $fp ); 
echo $output; 
?>
but everywhen user click link provided insteed of opennig file in his browser ,browser suggests him to download file while adboe is installed

where is my wrong.
any tip may be usefull.please help
thanks in advnace

Posted: Mon Jun 07, 2004 8:33 am
by dull1554
why even bother with this, the net effect is the same as just having their browser point directly to the pdf file, i dont see the logic in this, just wasting server processing power

Posted: Mon Jun 07, 2004 8:38 am
by patrikG
dull1554 wrote:why even bother with this, the net effect is the same as just having their browser point directly to the pdf file, i dont see the logic in this, just wasting server processing power
Not very helpful... :roll:

If you have a look at the [php_man]pdf[/php_man] functions in the manual and scroll down to the user-notes, you'll discover this:

Code: Select all

$buf = PDF_get_buffer($p);
$len = strlen($buf);
header("Cache-Control: no-store");
header("Cache-Control: no-cache");
header("Cache-Control: must-revalidate");
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=file.pdf");
Which might be of help.

Posted: Mon Jun 07, 2004 9:09 am
by Wayne
pdf's will only open in a browser if it supports and is set up to use Adobe as a plugin for the browser, not all browsers support this especially older browsers and some non Microsoft ones.

What browser is the user using?

Posted: Mon Jun 07, 2004 10:07 am
by dave420
patrikG - setting the filename through content-disposition can cause IE to spit out the "download" dialogue box. It's part of the security issues. As you're (possibly) hiding the extension of the file, it plays safe and asks you what to do.

Setting the content-type header is enough to let the browser know it's a PDF coming down the line. Any installed plugins will take that and render it for you.

Posted: Mon Jun 07, 2004 10:16 am
by patrikG
I assumed the guy who has problems with viewing the PDF is using IE and it sounds very much like a header() issue (alas, IE, alas, yet again :(). Can you reproduce the error on your machine?

Posted: Mon Jun 07, 2004 10:39 am
by dave420
(why does everyone hate IE? :-P)

Posted: Mon Jun 07, 2004 12:51 pm
by dull1554
well i hyave totally rebelled away from Microsoft....the only microsoft product i use is a wireless optical mouse and i dont know that i even trust that.....

Posted: Tue Jun 08, 2004 3:23 am
by dave420
too bad, dude :-P

Posted: Tue Jun 08, 2004 6:19 am
by dull1554
not really i've started to enjoy linux and freeBSD, and i dont really mind Debian that much either

Posted: Thu Jun 10, 2004 3:40 am
by dave420
Your loss! :-P