Home  >  Article  >  Backend Development  >  PHP decompress ZIP file

PHP decompress ZIP file

WBOY
WBOYOriginal
2016-07-25 08:42:46940browse
  1. function unzip($location,$newLocation)
  2. {
  3. if(exec("unzip $location",$arr)){
  4. mkdir($newLocation);
  5. for($i = 1;$i< count($arr);$i++){
  6. $file = trim(preg_replace("~inflating: ~","",$arr[$i]));
  7. copy($location.'/'.$file,$newLocation.'/'.$file);
  8. unlink($location.'/'.$file);
  9. }
  10. return TRUE;
  11. }else{
  12. return FALSE;
  13. }
  14. }
复制代码

用法:

  1. unzip('test.zip','unziped/test'); //File would be unzipped in unziped/test folder
  2. ?>
复制代码

PHP, ZIP


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn