title: How should the temporary file be saved when creating and download zip file using PHP?
body: <p>I wish to zip a directory on the server and download it to the user.  I've found great information on this site on how to zip the directory.</p>
  
  <p>The part that has me stumped is where to store the temporary file.  From what I've read, <code>zipArchive</code> requires that the zip file be saved on the server, and I can't download it without saving it.  Correct?</p>
  
  <p>I've seen solutions where they recommend saving it as "somename.zip", and then using <code>readfile()</code> along with the appropriate headers to download, and then using <code>unlink()</code> after the download to get rid of it.  But where to store "somename.zip" and what if there are collisions?</p>
  
  <p>So, then I started thinking that I should create a file with a random name in some temporary directory.  Or maybe I should use something like <code>tmpfile()</code>, but that returns a file handler and I don't know how that will work with zipArchive.</p>
  
  <p>For my application, the size of the directory is fairly small, and would like to not even write it to disk, but to memory instead.  Maybe something like <code>$tmp_handle = fopen('php://temp', 'r+');</code>, but again this returns a file handler and I don't know how that will work with zipArchive.</p>
  
  <p>How should the zip file created by zipArchive be temporary saved?</p>