title: Downloading a file in php doesn't work for pdf but works for text files
body: <p>I am trying to force download a file in my php program under a new name (new_name). I am changing the file name but keeping the extension the same as roginal file. This is part of my  code:</p>
  
  <pre><code>$original_filename = "attachments/20180315.log";
  $new_filename = "new_name." . pathinfo($original_filename, PATHINFO_EXTENSION);
  header("Content-Length: " . filesize($original_filename));
  header("Content-Transfer-Encoding: binary");
  header('Content-Disposition: attachment; filename="' . $new_filename . '"');
  header('Pragma: no-cache'); 
  
  readfile($original_filename);
  exit;           
  </code></pre>
  
  <p>My download is working fine when I am downloading a text file (i.e. in example above 20180315.log is a text file). When I try to do the same with a binary file (such as pdf) I am getting an empty new_name.pdf. </p>
  
  <p>Any suggestion?</p>