How To Display PDF File in PHP on Browser -

  • This function reads the file and writes it to the output buffer. It takes the filename as a parameter to read and return the number of bytes on success. Also, you can hide the error message by putting an @ in front of the readfile() function.

Example to show PDF file in PHP in HTML web page


$filename = "D:\wamp\www\myprojects\image1.pdf";
// Header
content type header("Content-type: application/pdf"); header("Content-Length: " . filesize($filename));
// Send the file to the browser.



Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store