title: PHP Zip File Corrupted
body: <p>I'm new here, so please bear with me. My problem is that when I create a zip file, and send it as a download, it gets corrupted somehow. The file itself that was created is perfectly fine. I have tried making a separate PHP file with the bare minimum PHP code required to test if it works, and it downloads with no corruption. This leads me to belive that the GET method also used on the page is messing with the download headers somehow. Here is my code if it helps:</p>
  
  <pre><code>&lt;?php
  
  $phar = new PharData('./Files/Toolbox.zip');
  // add all files in the project
  $phar-&gt;buildFromDirectory(dirname(__FILE__) . '/Files/Toolbox');
  chmod("./Files/Toolbox.zip", 0777);
  $file='./Files/Toolbox.zip';
  if (headers_sent()) {
      echo 'HTTP header already sent';
  } else {
      if (!is_file($file)) {
          header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
          echo 'File not found';
      } else if (!is_readable($file)) {
          header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
          echo 'File not readable';
      } else {
          header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
          header("Content-Type: application/zip");
          header("Content-Transfer-Encoding: Binary");
          header("Content-Length: ".filesize($file));
          header("Content-Disposition: attachment; filename=\"".basename($file)."\"");
          readfile($file);
          exit;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Also, the url looks like this if it helps:
      <a href="http://website.com/download.php?key=DOWNLOADKEY" rel="nofollow">http://website.com/download.php?key=DOWNLOADKEY</a></p>