12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace app\common\components;
- class Unzip{
- public function __construct(){
-
-
- }
- function transcoding($fileName){
- $encoding = mb_detect_encoding($fileName,['UTF-8','GBK','BIG5','CP936']);
- if (DIRECTORY_SEPARATOR == '/'){
- $filename = iconv($encoding,'UTF-8',$fileName);
- }else{
- $filename = iconv($encoding,'GBK',$fileName);
- }
- return $filename;
- }
-
- public function unzip($src_file, $dest_dir=false, $create_zip_name_dir=true, $overwrite=true){
- $fileList = array();
- $zip = new \ZipArchive;
- if ($zip->open($src_file) === TRUE) {
- if(!is_dir($dest_dir)) mkdir($dest_dir,0775,true);
- $docnum = $zip->numFiles;
- for($i = 0; $i < $docnum; $i++) {
- $statInfo = $zip->statIndex($i,\ZipArchive::FL_ENC_RAW);
- $filename = $this->transcoding($statInfo['name']);
- if($statInfo['crc'] == 0) {
-
- if(!is_dir($dest_dir.'/'.substr($filename, 0,-1))) mkdir($dest_dir.'/'.substr($filename, 0,-1),0775,true);
- } else {
-
- $fileList[] = $dest_dir.'/'.$filename;
- @copy('zip://'.$src_file.'#'.$zip->getNameIndex($i), $dest_dir.'/'.$filename);
- }
- }
- $zip->close();
- return $fileList;
- }else{
- return false;
- }
- }
- }
- ?>
|