如何用PHP代码解压一个ZIP文件?
- 内容介绍
- 文章标签
- 相关推荐
本文共计95个文字,预计阅读时间需要1分钟。
phpfunction unzip($location, $newLocation) { $command=unzip $location; exec($command, $arr); mkdir($newLocation); foreach ($arr as $i=> $line) { $file=trim(preg_replace(/inflating: ~/, , $line)); copy($location/$file, $newLocation/$file); }}
<?php function unzip($location,$newLocation){ if(exec("unzip $location",$arr)){ mkdir($newLocation); for($i = 1;$i< count($arr);$i++){ $file = trim(preg_replace("~inflating: ~","",$arr[$i])); copy($location.'/'.$file,$newLocation.'/'.$file); unlink($location.'/'.$file); } return TRUE; }else{ return FALSE; } } ?> //Use the code as following: <?php include 'functions.php'; if(unzip('zipedfiles/test.zip','unziped/myNewZip')) echo 'Success!'; else echo 'Error'; ?>
本文共计95个文字,预计阅读时间需要1分钟。
phpfunction unzip($location, $newLocation) { $command=unzip $location; exec($command, $arr); mkdir($newLocation); foreach ($arr as $i=> $line) { $file=trim(preg_replace(/inflating: ~/, , $line)); copy($location/$file, $newLocation/$file); }}
<?php function unzip($location,$newLocation){ if(exec("unzip $location",$arr)){ mkdir($newLocation); for($i = 1;$i< count($arr);$i++){ $file = trim(preg_replace("~inflating: ~","",$arr[$i])); copy($location.'/'.$file,$newLocation.'/'.$file); unlink($location.'/'.$file); } return TRUE; }else{ return FALSE; } } ?> //Use the code as following: <?php include 'functions.php'; if(unzip('zipedfiles/test.zip','unziped/myNewZip')) echo 'Success!'; else echo 'Error'; ?>

