title: output buffering for php file download
body: <p>Can I do something like this?</p>
  
  <pre><code>ob_start();
  header("Content-Type: application/msword");
  header("Content-Disposition: attachment; filename=".$title);
  header("Content-Length: ".$size);
  header("Content-Transfer-Encoding: binary");
  readfile($path);
  ob_end_flush();
  </code></pre>
  
  <p>Currently I am getting the correctly named file to download, but the contents of the file is the html output from the php that contains the above code.</p>
  
  <p>I have verified the $path to be correct.  Would a bad $size cause this to happen? 
  I have also tried to ob_flush() directly after ob_start().</p>
  
  <p>EDIT: Current Code Below:</p>
  
  <pre><code>if (file_exists($path)){
      ob_start();
      header("Content-Type: application/msword");
      header("Content-Disposition: attachment; filename=".$title);
      header("Content-Length: ".filesize($path));
      header("Content-Transfer-Encoding: binary");
      readfile($path);
      ob_end_flush();
      die();
      } else die ("Not Found");
  </code></pre>
  
  <p>Above code results in the same problem. File is downloaded, named correctly, apparently exists and with correct size, yet contents of the file is the html output of the page.</p>
  
  <p>Thanks in advance</p>
  
  <p>I just noticed that this is at the very end of the file that downloads (incorrectly):
  "int (14) content"</p>
  
  <p>But I am not knowingly outputting this anywhere in my code.</p>