title: cannot download pdf in PHP
body: <p>I want to force browser to download a PDF file from server using <code>readfile</code> in php.
  This is my code:</p>
  <pre><code>$file = '/DIR/file.pdf';
              if (file_exists($file)) {
                  header('Content-Description: File Transfer');
                  header('Content-Type: application/octet-stream');
                  header('Content-Disposition: attachment; filename=&quot;'.basename($file).'&quot;');
                  header('Expires: 0');
                  header('Cache-Control: must-revalidate');
                  header('Pragma: public');
                  header('Content-Length: ' . filesize($file));
                  readfile($file);
                  exit;
              }
  </code></pre>
  <p>After that browser shows me some unknown characters instead of downloading the PDF file. I tried different browsers and none of them did work. <strong>What should I do to force the browser to download the file?</strong>
  <br>
  The output is this:</p>
  <p><img src="https://img.techpowerup.org/200724/capture236.png" alt="Text" /></p>
  <p>Please note that the file downloads correctly if I type file dir in in the browser.</p>