title: PHP generated Excel file is different when downloaded
body: <p>I have a PHP file that generates xls files using the module found at <a href="http://pear.php.net/package/Spreadsheet_Excel_Writer/" rel="nofollow noreferrer">http://pear.php.net/package/Spreadsheet_Excel_Writer/</a></p>
  
  <p>I can create the sample document just fine and when I open it, it looks fine.</p>
  
  <p>My next step it to turn it into a downloadable link. To do that, I did this:</p>
  
  <pre><code>    $mimeType = "application/vnd.ms-excel";
      $file_name = "test.xls";
      $file_path = "/tmp/".$file_name;
      header("Pragma: public");
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Content-Type: application/force-download");
      header("Content-Type: application/octet-stream");
      header("Content-Type: application/download");
      header('Content-Type: application/' . $mimeType);
      header('Content-Length: '.$size);
      header("Content-Disposition: attachment;filename=$file_name ");
      header("Content-Transfer-Encoding: binary ");
  
      // open the file in binary read-only mode
      // display the error messages if the file can´t be opened
      $file = &amp; fopen($file_path, 'rb');
  
      if ($file) {
          // stream the file and exit the script when complete
          fpassthru($file);
          exit;
  
      } else {
          echo $err;
      }
  </code></pre>
  
  <p>When I download the file however, it contains a lot of garbage data both in Excel and OpenOffice. The diff says that then binary file in the /tmp folder and the downloaded file are different from each other. I'm guessing that it has something to do with the headers or with fpassthru but I haven't had much luck with debugging the issue.</p>
  
  <p>Any ideas on what the problem is?</p>