title: Downloading an Excel File with php
body: <p>I am trying to download an excel file to the client that I save on the server first (for backup purposes). The problem is I get a completely different file server side than I do client side. The server side is correct, the client side lists my sql queries and the time it takes. Note the xlsx is multiple sheets in one workbook and it needs to be that way.</p>
  
  <pre><code>public static function generate()
      {
          //Override the max execution time because our report takes longer than 30 seconds to run
          ini_set("max_execution_time", 300);
  
          $objPHPExcel = new PHPExcel();
  
          $objPHPExcel = ErsReport::generateDemographics($objPHPExcel);
          $objPHPExcel = ErsReport::generateWorkLocationTab($objPHPExcel);
          $objPHPExcel = ErsReport::generateDisabilityCategoryTab($objPHPExcel);
  
          $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
          $objWriter-&gt;save('ERS Reports\SpeedERS_'.date("Y_m_d").'.xlsx');
          //$objWriter-&gt;save('SpeedERS.xlsx');
      }
  
      public static function download()
      {
          header ('Content-Type: application/vnd.ms-excel; charset=utf-8');
          header ('Content-Disposition: attachment; filename="ERS Reports\SpeedERS_'.date("Y_m_d").'.xlsx"'); 
          header("Expires: 0");
          header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
          header("Cache-Control: private",false);
          readfile('ERS Reports\SpeedERS_'.date("Y_m_d").'.xlsx');
      }
  </code></pre>
  
  <p>I call generate then download. The generate shows the correct data. 
  <img src="https://i.stack.imgur.com/itv0X.png" alt="Correct SpreadSheet"></p>
  
  <p>When I call download it shows improper data and only one page.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The function calling generate &amp; download.</p>
  
  <pre><code>    function submitERSReport (formLocation) {
          {{ErsReport::generate();}}
          {{ErsReport::download();}}
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/n3eSo.png" alt="Incorrect SpreadSheet"></p>