title: How do I output EXCEL file directly to user without storing locally?
body: <p>I'm using PHPExcel to generate excel files (crazy right ?) with information I get from a database, the thing is whenever I create the file it is saved in the server and then I just send a link to that file to the user so he can access it.</p>
  
  <p>I doubt this is the right way of doing it, what I'm looking for is to just send the file to the browser without saving it on the server.</p>
  
  <p><strong>How do I output EXCEL file directly to user without storing locally?</strong></p>
  
  <p>Code:</p>
  
  <pre><code>$fileName  = "Request_" . $idRequest . "_Update.xls";
  $objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
  $objWriter-&gt;save($fileName);
  $objPHPExcel = PHPExcel_IOFactory::load($fileName);
  
  
  echo json_encode(array(
          "ExitCode" =&gt; 0,
          "Message" =&gt; "Success",            
          "data" =&gt; $request,
          "File" =&gt; "../reports/$fileName"
      ));
  </code></pre>
  
  <p>Once i receive <code>File</code> in the <code>$.ajax</code> call that receives it just add it to an anchor tag:</p>
  
  <pre><code>$.ajax({
         ...
         success : function(response){
             $('#container').append('&lt;a href="'+response.File+'"&gt;Here is your file&lt;/a&gt;
         }
  </code></pre>