View Full Version : opening docs/pdfs

09-13-2011, 01:27 AM
Because I need to login protect some files, I'm using a PHP script to check login and then load the file.

My question is how should I load the file?

i.e. the user requested exam.pdf. Behind the scenes (with rewrites) I load view_file.php

Should view_file using fopen or similar to load the file?

It will mostly be pdf and word files but could be other so I'll probably have to check the extension.

09-13-2011, 01:29 AM
The best option is to use readfile() (http://php.net/readfile). Check the manual page example for the headers you need to send.