title: zip files and download using php
body: <p>I have a question</p>
  
  <p>I have looked all over stacked overflow, on how to make a zip out of multiple files, and I got this code:</p>
  
  <pre><code>    &lt;?php
          $data = $_POST['data'];
          $zip = new ZipArchive();
          $zip_name = dirname(__FILE__)."/billeder.zip"; // Zip name
          $zip-&gt;open($zip_name,  ZipArchive::CREATE);
  
          foreach ($data as $file) {
              $path = dirname(__FILE__)."/".$file;
              $zip-&gt;addFromString(basename($path),  file_get_contents($path));  
          }
  
          $zip-&gt;close();
  
          header('Content-Type: application/zip');
          header('Content-disposition: attachment; filename='.basename($zip_name));
          header('Content-Length: ' . filesize($zip_name));
          ob_clean();
          flush();
          readfile($zip_name);
          unlink($zip_name);
      ?&gt;
  </code></pre>
  
  <p>the post data look something like this:</p>
  
  <pre><code>["Billede_008.JPG","Billede_011.JPG"]
  </code></pre>
  
  <p>a list of images.</p>
  
  <p>My problem is that, I don't receive the zip file, when posting to the url.
  I have checked that it got the post data, I've checked that all files in the post exists, and I have checked that the files were added to the zip.</p>
  
  <p><a href="https://i.stack.imgur.com/jLHu4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jLHu4.png" alt="here is the response data from chrome"></a> 
  here is the response from chrome. as you can see there's nothing wrong with the response, but I still don't get the zip.</p>
  
  <p>Can anyone see, what I'm doing wrong?</p>