Home >Backend Development >PHP Tutorial >PHP code to Unzip a Zip file

PHP code to Unzip a Zip file

WBOY
WBOYOriginal
2016-07-25 08:42:48852browse
  1. function unzip($location,$newLocation){
  2. if(exec("unzip $location",$arr)){
  3. mkdir($newLocation);
  4. for($i = 1;$i< count($arr);$i++){
  5. $file = trim(preg_replace("~inflating: ~","",$arr[$i]));
  6. copy($location.'/'.$file,$newLocation.'/'.$file);
  7. unlink($location.'/'.$file);
  8. }
  9. return TRUE;
  10. }else{
  11. return FALSE;
  12. }
  13. }
  14. ?>
  15. //Use the code as following:
  16. include 'functions.php';
  17. if(unzip('zipedfiles/test.zip','unziped/myNewZip'))
  18. echo 'Success!';
  19. else
  20. echo 'Error';
  21. ?>
复制代码

Unzip, Zip, PHP


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
Previous article:PHP gets current page URLNext article:PHP gets current page URL