title: PHP zipped directory becomes cpgz file when extracted
body: <p>I've checked a few questions before posting, including the following:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/11454158/zipped-file-with-php-results-in-cpgz-file-after-extraction">Zipped file with PHP results in cpgz file after extraction</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/12411481/php-download-script-creates-unreadable-zip-file-on-mac">PHP Download Script Creates Unreadable ZIP File on Mac</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/11495103/opening-downloaded-zip-file-creates-cpgz-file">Opening downloaded zip file creates cpgz file?</a></p></li>
  </ul>
  
  <p>While testing on a local server everything worked as intended, however when we uploaded to the live site the downloaded zip files opened as <code>.cpgz</code> files.</p>
  
  <p>We're populating a SELECT menu (named "<strong>Conference</strong>") in an html form with the folder names in our "<code>Conferences</code>" directory (i.e. Asset_Management).</p>
  
  <p>The PHP concatenates into a link as such:</p>
  
  <pre><code>&lt;a href="zip_folders.php?directtozip=' . $_POST["Conference"] . '"&gt;Download All As Zip&lt;/a&gt;
  </code></pre>
  
  <p>Our zipping code sets up the zip file:</p>
  
  <pre><code>&lt;?php
  // WARNING
  // This code should NOT be used as is. It is vulnerable to path traversal. https://www.owasp.org/index.php/Path_Traversal
  // You should sanitize $_GET['directtozip']
  // For tips to get started see https://stackoverflow.com/questions/4205141/preventing-directory-traversal-in-php-but-allowing-paths
  
  //Get the directory to zip
  $filename_no_ext= $_GET['directtozip'];
  
  // we deliver a zip file
  header("Content-Type: archive/zip");
  
  // filename for the browser to save the zip file
  header("Content-Disposition: attachment; filename=$filename_no_ext".".zip");
  
  // get a tmp name for the .zip
  $tmp_zip = tempnam ("tmp", "tempname") . ".zip";
  
  //change directory so the zip file doesnt have a tree structure in it.
  chdir('user_uploads/'.$_GET['directtozip']);
  
  // zip the stuff (dir and all in there) into the tmp_zip file
  exec('zip '.$tmp_zip.' *');
  
  // calc the length of the zip. it is needed for the progress bar of the browser
  $filesize = filesize($tmp_zip);
  header("Content-Length: $filesize");
  
  // deliver the zip file
  $fp = fopen("$tmp_zip","r");
  echo fpassthru($fp);
  
  // clean up the tmp zip file
  unlink($tmp_zip);
  ?&gt;
  </code></pre>
  
  <p>But when I unzip the file it becomes a <code>.cpgz</code> file.</p>
  
  <p><strong>Why might this work on our local server and not our remotely hosted site?</strong></p>
  
  <p>EDIT: I think the <code>exec()</code> command might not be portable, but I'm not sure how to replace that. </p>