欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Unzip一个Zip文件的PHP代码

程序员文章站 2022-05-16 10:37:02
...
  1. function unzip($location,$newLocation){
  2. if(exec("unzip $location",$arr)){
  3. mkdir($newLocation);
  4. for($i = 1;$i $file = trim(preg_replace("~inflating: ~","",$arr[$i]));
  5. copy($location.'/'.$file,$newLocation.'/'.$file);
  6. unlink($location.'/'.$file);
  7. }
  8. return TRUE;
  9. }else{
  10. return FALSE;
  11. }
  12. }
  13. ?>
  14. //Use the code as following:
  15. include 'functions.php';
  16. if(unzip('zipedfiles/test.zip','unziped/myNewZip'))
  17. echo 'Success!';
  18. else
  19. echo 'Error';
  20. ?>
复制代码

Unzip, Zip, PHP