title: How do I properly send a PDF file through PHP?
body: <p>I am trying to send a PDF file. Here is the code that is executing:</p>
  
  <pre><code>$file_path = '/path/to/file/filename.pdf'
  $file_name = 'filename.pdf'
  
  header("X-Sendfile: $file_path");
  header("Content-type: application/octet-stream");
  header("Content-Disposition: attachment; filename='$filename'");
  readfile($file_path):
  </code></pre>
  
  <p>whenever I download the file directly, it is fine. however when I try to download the file via this script, a file downloads that cannot be opened. my pdf reader tells me it cannot open a file of type 'text/plain'. I also tried setting the <code>Content-type</code> to <code>application/pdf</code> , but I get the same errors. What am I doing wrong here?</p>