Display PDF in browser via PHP

Display PDF in browser

Sometimes it is required to hide the actual PDF file name for security reason. So using a webpage you can display PDF in browser without knowing the actual URL.

Example source:

<?php
$file = 'path-to-pdf-file/myFile.pdf';
$filename = 'download.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
@readfile($file);
?>

Save this file as pdf.php and run in a browser. You can see the PDF displaying on the browser.

For any types of queries, you can contact us on info@namasteui.com.

You may like:  Significance Of PHP To Blog And Website Development

Leave a Reply

Your email address will not be published. Required fields are marked *