开发者

How to extract a zip file and save files to folder and file name to database using PHP?

开发者 https://www.devze.com 2023-01-13 22:44 出处:网络
How to extract a zip file and save files to folder and file name to database usi开发者_StackOverflow中文版ng PHP?This tutorial will teach you how to do this -> http://net.tutsplus.com/articles/news/ho

How to extract a zip file and save files to folder and file name to database usi开发者_StackOverflow中文版ng PHP?


This tutorial will teach you how to do this -> http://net.tutsplus.com/articles/news/how-to-open-zip-files-with-php/


Here it is:

$zip = zip_open("xyz.zip");
if ($zip) {
  while ($zip_entry = zip_read($zip)) {
    $fp = fopen("zip/".zip_entry_name($zip_entry), "w");

    // write the file name zip_entry_name($zip_entry) to DB here

    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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消