title: PDF-Download with PHP --> ERR_CONTENT_LENGTH_MISMATCH
body: <p>I would like to download a PDF via PHP from my server, which is also uploaded via PDF. Although it works with some files I get the following error message with individual files:</p>
  
  <p><strong>ERR_CONTENT_LENGTH_MISMATCH</strong></p>
  
  <p>This is my download function:</p>
  
  <pre><code>if($_GET['funktion'] == 'downloadallgemein')
   {
  
          $filename = basename($dateiname);
          $path = '/kunden/261105_71522/webseiten/dev.delst/uploads/'.$filename.''; // the file made available for download via this PHP file
          if (file_exists($path)) {
                  $mm_type="application/octet-stream"; // modify accordingly to the file type of $path, but in most cases no need to do so
  
                  header("Pragma: public");
                  header("Expires: 0");
                  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                  header("Cache-Control: public");
                  header("Content-Description: File Transfer");
                  header("Content-Type: " . $mm_type);
                  header("Content-Length: " .(string)(filesize($path)) );
                  header('Content-Disposition: attachment; filename="'.basename($path).'"');
                  header("Content-Transfer-Encoding: binary\n");
  
                  readfile($path); // outputs the content of the file
  
                  exit();
          }
  
          else
          echo'Datei wurde nicht auf dem Server gefunden';
   }  
  </code></pre>
  
  <p>If I remove <strong>header("Content-Length: " .(string)(filesize($path)) );</strong> the download works, but the PDF file is then broken and can not be opened.</p>
  
  <p>The path is correct and the file is located on the server. So the upload works..</p>
  
  <p>What am I doing wrong? </p>