How to open a PDF files in web browser using PHP?

<?php

  

// The location of the PDF file

// on the server

$filename = "/doc.pdf";

  

// Header content type

header("Content-type: application/pdf");

  

header("Content-Length: " . filesize($filename));

  

  // Send the file to the browser.

readfile($filename);

?> 



 Example 1:

this examples displays a format and explains every section of code

<?php
  
// The location of the PDF file
// on the server
$filename = "/path/to/the/file.pdf";
  
// Header content type
header("Content-type: application/pdf");
  
header("Content-Length: " . filesize($filename));
  
// Send the file to the browser.
readfile($filename);
?> 

Output:

Comments

Popular posts from this blog

Table based design and Table less design

How to Move a WordPress Site from Localhost to a Live Server

Web Programming