title: PHPWord any way to not write file to disk when downloading file
body: <p>I'm using PHPWord to generate Word documents, and I'm hoping someone can help on this. The way its set up now, an ajax request is sent to my server from the browser requesting the PHPWord document to be built. The document is built, and stored in a file on the server with this code:</p>
  
  <pre><code>$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
  $fileName = $picklistDetails['file_name'] . ".docx";
  $filePath = '../users/' . $userId . "_word_" . $fileName;
  $objWriter-&gt;save($filePath); 
  </code></pre>
  
  <p>To allow the user to download the file, once the ajax request succeeds i use window.location to send the user to a page that puts the word document together with this (allowing the download to commence):</p>
  
  <pre><code>$fileName = $this-&gt;session-&gt;word_file_name;
  $filePath = $this-&gt;session-&gt;word_file_path;
  
  header("Cache-Control: public");
  header("Content-Description: File Transfer");
  header("Content-Disposition: attachment; filename=" . $fileName);
  header("Content-Transfer-Encoding: binary");    
  readfile($filePath);
  </code></pre>
  
  <p>This all works great, the only problem is i would really rather the file not have to be saved to the server before the download. I've been researching PHPWord and as per this post (<a href="https://stackoverflow.com/questions/11476058/auto-download-the-file-attachment-using-phpword">Auto download the file attachment using PHPWord</a>) theres some discussion of how you can send the file to php's output stream instead of writing it to disk, but because building the word document is done in ajax and then a separate page is used to download it, i don't think this would work. Am i wrong?</p>
  
  <p>Also in this post (<a href="https://stackoverflow.com/questions/49505557/save-generated-file-to-database-phpword">Save Generated File to database PHPWORD</a>) there is a description of how to store it to a DB, but there's still the intermediate step of a file on the server, which i need to avoid.</p>
  
  <p>Is there some way I can modify</p>
  
  <pre><code>$objWriter-&gt;save($filePath); 
  </code></pre>
  
  <p>to not write it to disk and instead save it to a variable or something? Then I could maybe store in a database where I could encrypt it.</p>
  
  <p>Any help would be appreciated. I'm kind of a beginner php programmer so detailed help would be much appreciated. have a good day.</p>