Extract .zip files using PHP [closed]

有些话、适合烂在心里 提交于 2019-12-06 03:26:30

问题


How can I extract .zip (100%), using PHP?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/5653130/extract-zip-files-using-php

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