Normally web browser decides a file to be downloaded or opened within a tab based on various types of headers a programming language passes. These headers define content composition in form of type, Disposition, Transfer-Encoding.
So PHP doesn’t actually read the file but sends signals for the web browser to render it. Here is how it looks when using PHP to display a PDF file on Chrome.
header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="my_file.pdf"'); header('Content-Transfer-Encoding: binary'); header('Accept-Ranges: bytes'); @readfile('my_file.pdf');
$filename = "/path/to/my_file.pdf"; header("Content-type: application/pdf"); header("Content-Length: " . filesize($filename)); readfile($filename);