title: How to Zip the image file and extract it using PHP? My code yields corrupt extraction
body: <p>i have a form in which user can upload 100 mb file which results delay in upload, hence I decided to first zip the image on form submit and then upload it on server and then extract it on server. so that loading process decreases, Hence for this I have used a script which is as follows:</p>
  
  <pre><code>&lt;?php
  $zip = new ZipArchive();
  $filename = "newzip.zip";
  
  if ($zip-&gt;open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
     exit("cannot open &lt;$filename&gt;\n");
  }
  $zip-&gt;addFromString("myfile.jpeg", 
  "This is the first file in our ZIP, added as 
  firstfile.txt.\n");
  
  echo "numfiles: " . $zip-&gt;numFiles . "\n";
  $zip-&gt;close();
  
  $zip1 = zip_open("newzip.zip");
  if ($zip1) {
    while ($zip_entry = zip_read($zip1)) {
      $fp = fopen(zip_entry_name($zip_entry), "w");
      if (zip_entry_open($zip1, $zip_entry, "r")) {
        $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
        fwrite($fp,"$buf");
        zip_entry_close($zip_entry);
        fclose($fp);
      }
    }
    zip_close($zip1);
    unlink("newzip.zip");
  }
  ?&gt;
  </code></pre>
  
  <p>Now here from the above code I get the image extracted, but after extraction the size of image is reduced to 61 bytes and is corrupt i.e. it cannot be viewed.</p>
  
  <p>What could be wrong with this code please guide me</p>