Page 1 of 1

How to display a pdf file

Posted: Wed Jul 30, 2008 6:41 am
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

Re: How to display a pdf file

Posted: Wed Jul 30, 2008 8:11 am
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.

Re: How to display a pdf file

Posted: Wed Jul 30, 2008 8:24 am
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.