PHP Include

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rache2000
Forum Newbie
Posts: 3
Joined: Tue May 11, 2004 3:53 pm
Location: United States

PHP Include

Post by rache2000 »

Hello everyone, I just found this website. I work with macromedia software and I tried this question on their forum, and no one knew the answer. I built and manage a site http://www.centurionams.com The site is built using php, css, and flash. The template is the same on every page, and I use <?php include()?> to repeat objects such as the navigation menu, images, and body content. most of the included files either end in .php, or .inc. Now to my question. The login area for clients contains pdf files located within other folders and directories. I tried using the php include tag and I get a parse error. Can pdf files be included with php?, and if so can someone tell me how to do this? If it can not be done let me know.

Thanks for any help offered
:roll:
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

you can link to them, but i dont think they can be included into an html page
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the include and require functions will cause php to attempt parsing of the file specified. Depending on what you are doing with them, try using readfile() in combination with several header() calls stating that the page is an inline pdf file.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

PDFs have a different encoding to a simple HTML-page. You will need to indicate to the browser what you're passing to it, otherwise it's Goobledigook and the browser displays it as such. With HTML it's done with <DOCTYPE ...> (and most browser default to HTML anyway.)

No browser I know of has an inbuilt PDF-reader, thus the browser relies on an external application. You need to specify that with MIME (see this tutorial) and pass it to the browser. For an example see viewtopic.php?t=19670 - note that you'll have to pass the appropriate MIME format in

Code: Select all

header("Content-type: application/octet-stream");
(in this example an octet-stream). Replace that with the pdf-MIME format.

You can't have both HTML and PDF in one page unless you make use of frames - which I haven't tried, but it should theoretically be possible (but a "dirty" solution).
rache2000
Forum Newbie
Posts: 3
Joined: Tue May 11, 2004 3:53 pm
Location: United States

PHP/Pdf Include

Post by rache2000 »

:P Thanks for the information from everyone. I understand how it works now. I set up a quick demo using the headers and readfile function, and it worked.

Thanks again
Rachael
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

:)
Post Reply