andrew2704 Posted March 5, 2010 Share Posted March 5, 2010 I understand that if I want to keep uploaded files secure I need to save them outside of the web root. I have managed to do that. The question is, how do I display those files in a browser window? Usually I would use header() to display but I don't know how to do that with files outside of the web root. Any suggestions in terms of how best to upload, secure and then display PDFs without exposing them to other users other than the one accessing them. One forum suggested making a temporary copy for the browser to access. Firstly I don't know how to do that and secondly, surely while the temporary file is there it is exposed to other users? Your help would be much appreciated! Link to comment https://forums.phpfreaks.com/topic/194205-how-do-i-display-pdfs-stored-outside-of-web-root/ Share on other sites More sharing options...
ferdi Posted March 5, 2010 Share Posted March 5, 2010 Use the readfile() function, and then set a header stating it's a pdf document. Link to comment https://forums.phpfreaks.com/topic/194205-how-do-i-display-pdfs-stored-outside-of-web-root/#findComment-1021770 Share on other sites More sharing options...
andrew2704 Posted March 5, 2010 Author Share Posted March 5, 2010 Thanks for pointing me in the right direction. I am not sure that I understand the process - how readfile and header work together. I am assuming my code will look something like this: <?php header('Content-type: application/pdf'); readfile('original.pdf'); ?> How do header and readfile interact? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/194205-how-do-i-display-pdfs-stored-outside-of-web-root/#findComment-1021778 Share on other sites More sharing options...
ferdi Posted March 5, 2010 Share Posted March 5, 2010 That's correct, you can do it like that. The readfile() function doesn't interact with the header, it's a function that just outputs the files content to the page. "Reads a file and writes it to the output buffer." - php.net/readfile Link to comment https://forums.phpfreaks.com/topic/194205-how-do-i-display-pdfs-stored-outside-of-web-root/#findComment-1021786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.