Jump to content

extract a remote zip file with php


fluid

Recommended Posts

Hi I am trying to grab a remote zip file then extract it but it is trying to extract it before it has trasnfered so I end up with a complete zip file but an xml file of 0 bytes.  The code I have is:

 

 

// read the file

$image = file_get_contents("http://www.examplesite.com/zip");

// write the file

file_put_contents("zips/filename.zip", $image);

// extract the file

$zip = zip_open("zips/filename.zip");

if ($zip) {

  while ($zip_entry = zip_read($zip)) {

    $fp = fopen("zips/".zip_entry_name($zip_entry), "w");

    if (zip_entry_open($zip, $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($zip);

}

 

 

 

Many thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/194889-extract-a-remote-zip-file-with-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.