Search code examples
javascriptphplaraveliframepdf.js

iframe set src value from a php file without show file path in source code


In my Laravel project I'm using PDF.JS for display some PDF documents. I'm trying to hide the pdf path passing a php file in the src field of iframe.

In my view:

<iframe id="reader" src="http://server.dev/Wrapper.php"></iframe>

In my Wrapper.php:

<?php
//here I will call some methods to compose right uri
echo "http://server.dev/libs/pdfjs/web/viewer.html?file=http://server.dev/repository/ex.pdf";
?>

It doesn't work, It display the url inside the body tag of iframe:

<iframe id="reader" src="http://server.dev/Wrapper.php">
    <html>
        <head>
        </head>
        <body>
            http://server.dev/libs/pdfjs/web/viewer.html?file=http://server.dev/repository/ex.pdf
        </body>
    </html>
</iframe>

It's possible to display the pdf file without show the pdf path directly in the source code?

Thanks


Solution

  • Put this code in your Wrapper.php file

      header("Content-type: application/pdf");
      header("Content-Length: ".filesize($filepath.$filename));
      ob_end_flush();
      @readfile($filepath.$filename);