title: How to open a PDF file in browser using PHP
body: <p>I'm new to PHP. I'm trying a test to see if I can open a PDF file in a directory on an Apache server. There is no .htaccess for the directory. When I execute the code I get a "Failed to load PDF document" error. The $filePath is fine. Any ideas would be greatly appreciated.</p>
  
  <pre><code>$filePath = '/home/xxx/public_html/xFiles/Reports/Test.pdf';
  if (file_exists($filePath)) {
      echo "The file $filePath exists";
  } else {
      echo "The file $filePath does not exist";
      die();
  }
  $filename="Test.pdf";
  
  header('Content-type:application/pdf');
  header('Content-disposition: inline; filename="'.$filename.'"');
  header('content-Transfer-Encoding:binary');
  header('Accept-Ranges:bytes');
  readfile($filePath);
  </code></pre>