Extract .zip files using PHP [closed]

二次信任 提交于 2019-12-04 08:45:52

If you have zziplib installed, you can use this code:

<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
  $zip->extractTo('/my/destination/dir/');
  $zip->close();
  echo 'ok';
} else {
  echo 'failed';
}
?>

Make sure the user executing php (usually nobody, apache or httpd) have writing privileges on destination dir.

Use the Zip API. The algorithm for this is:

  1. Open file with zip_open
  2. Read directory entry with zip_read; if false goto step 8
  3. Get the name with zip_entry_name
  4. Open the entry with zip_entry_open
  5. Get the data with zip_entry_read, and store how & where you want
  6. Close the entry with zip_entry_close
  7. Goto step 2
  8. Close file with zip_close

Hope this helps,

Phil Lello

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!