alesgirl Posted February 10, 2008 Share Posted February 10, 2008 Hi, I've been going around in circles and have tried a few things to display a PDF in an iFrame even though the folder is password-protected. I couldn't find a way to enter the password before displaying the PDF. I'd like for the folder that contains the PDFs is password protected and would like to not allow someone get access to the entire folder once they see the path in the source of the page. Is there a way to accomplish this using PHP? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/ Share on other sites More sharing options...
Stooney Posted February 10, 2008 Share Posted February 10, 2008 why not just include the pdf from above the webroot? no password needed say your site is in /htdocs/site and the pdf is in /htdocs/pdf include("../pdf/file.pdf"); That way there never can be a direct link to the pdf, your script has to include it. Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/#findComment-463489 Share on other sites More sharing options...
alesgirl Posted February 10, 2008 Author Share Posted February 10, 2008 I just tried what you suggested and it's not working for me. It says that the file can't be found. I have this in my HTML page too and am not using an include, but either way it's not working: <iframe src= "../../../private/pdf/pdf1.pdf#toolbar=0" width="800" height="600"></iframe> Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/#findComment-463512 Share on other sites More sharing options...
darkfreaks Posted February 10, 2008 Share Posted February 10, 2008 <?php $p = PDF_new(); /* open new PDF file; insert a file name to create the PDF on disk */ if (PDF_begin_document($p, "", "") == 0) { die("Error: " . PDF_get_errmsg($p)); } PDF_set_info($p, "Creator", "hello.php"); PDF_set_info($p, "Author", "Rainer Schaaf"); PDF_set_info($p, "Title", "Hello world (PHP)!"); PDF_begin_page_ext($p, 595, 842, ""); $font = PDF_load_font($p, "Helvetica-Bold", "winansi", ""); PDF_setfont($p, $font, 24.0); PDF_set_text_pos($p, 50, 700); PDF_show($p, "Hello world!"); PDF_continue_text($p, "(says PHP)"); PDF_end_page_ext($p, ""); PDF_end_document($p, ""); $buf = PDF_get_buffer($p); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=hello.pdf"); print $buf; PDF_delete($p); ?> Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/#findComment-463518 Share on other sites More sharing options...
alesgirl Posted February 10, 2008 Author Share Posted February 10, 2008 Thanks. I'll install the PDF library and test out the code. Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/#findComment-463519 Share on other sites More sharing options...
darkfreaks Posted February 10, 2008 Share Posted February 10, 2008 oh crud that makes a pdf Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/#findComment-463525 Share on other sites More sharing options...
resago Posted February 10, 2008 Share Posted February 10, 2008 load it into a string send a pdf out header print string $buf=file_get_contents('folder/yourpdf'); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=hello.pdf"); print $buf; Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/#findComment-463528 Share on other sites More sharing options...
alesgirl Posted February 11, 2008 Author Share Posted February 11, 2008 load it into a string send a pdf out header print string $buf=file_get_contents('folder/yourpdf'); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=hello.pdf"); print $buf; Thank you very, very much! It works perfectly!!! Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/#findComment-463835 Share on other sites More sharing options...
alesgirl Posted February 11, 2008 Author Share Posted February 11, 2008 The solution works great except with some browsers, the PDF is downloaded to disk? Is there any way to override that? I looked at some other websites, like my bank, and they can't seem to display the PDF in the window with some browsers. So maybe that's just the way it is. :-( If anyone can confirm this for me, I'd appreciate it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/#findComment-463893 Share on other sites More sharing options...
resago Posted February 12, 2008 Share Posted February 12, 2008 if the client doesn't have a pdf viewer, it will ask to save the file. no other way to do it though. its up to the client to have the pdf reader. Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/#findComment-464540 Share on other sites More sharing options...
alesgirl Posted February 12, 2008 Author Share Posted February 12, 2008 OK, thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/90408-how-can-i-display-a-pdf-on-a-page-if-the-pdf-folder-is-protected/#findComment-464676 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.