How to display a pdf file

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
Regis
Forum Newbie
Posts: 2
Joined: Wed Jul 30, 2008 6:36 am

How to display a pdf file

Post by Regis »

I am new to php.
I need to display a pdf file that reside on the server.
The name of the file that need to be displayed is only known at run time so I need to do it in php code.

Thanks,

Regis
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: How to display a pdf file

Post by Dynamis »

Well there are really two options here.

First, if you stored the pdf in a database, you need to set the header content-type to the appropriate MIME type. In the case of a pdf, the type is application/pdf. Then you just write the bytes to the screen.

Other option, if you have the file stored physically on the server as example.pdf in some folder. You can just link to the file and that will allow it to open in the browser.
Regis
Forum Newbie
Posts: 2
Joined: Wed Jul 30, 2008 6:36 am

Re: How to display a pdf file

Post by Regis »

Yes, I just figured out that it was realy simple after all.
I just echo a <a> tag with the filename in it.

As you probably figured out, I am new to web programming.

My issue is now resolved.

Thanks.
Post Reply