当前位置:Gxlcms > PHP教程 > Unzip一个Zip文件的PHP代码

Unzip一个Zip文件的PHP代码

时间:2021-07-01 10:21:17 帮助过:21人阅读

  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

人气教程排行