PHP Implementation Unzip zip file
1 functionZip$filename,$path)2 {3 //$filename = ' test.zip ';4 //$path = './document/2016-05-11/test.zip ';5     $path _all=$_server[' Document_root ']. Sp_get_asset_upload_path (Mb_substr ($path, 2) ;//think_cmf get file path strength6     $file _name_head= Mb_substr ($path, 0,Strrpos($path, "/"));7     if(!file_exists($path _all)) {8         Echo' File does not exist ';9     }Ten     //Z transcoding converts the file name and path to the default gb2312 encoding of the Windows system, otherwise it will not be read One     $filename=Iconv(' Utf-8 ', ' gb2312 ',$filename); A     $path _all=Iconv(' Utf-8 ', ' gb2312 ',$path _all); -     //opening a compressed package -     $resource= Zip_open ($path _all); the     $i= 0; -      while($dir _resource= Zip_read ($resource)) { -         if(Zip_entry_open ($resource,$dir _resource)) { -             $file _name=substr($path _all, 0,Strrpos($path _all, "/")) . ‘/‘ . Zip_entry_name ($dir _resource); +             $dir _name= Zip_entry_name ($dir _resource); -             $file _path=substr($file _name, 0,Strrpos($file _name, "/")); +         } A         if(!Is_dir($file _path)) { at             mkdir($file _path, 0777,true); -         } -         if(!Is_dir($file _name)) { -             $file _size= Zip_entry_filesize ($dir _resource); -             //Max Read 10M, if file is too large, skip unzip, continue next -             if($file _size< (1024 * 1024 * 10)) { in                 $file _content= Zip_entry_read ($dir _resource,$file _size); -                 file_put_contents($file _name,$file _content); to             } +             //Close the current -Zip_entry_close ($dir _resource); the         } *         $dir _name=Iconv(' gb2312 ', ' utf-8 ',$dir _name); $         $data[$i][filename] =$file _name_head. ‘/‘ .$dir _name;Panax Notoginseng         $data[$i[' size '] =$file _size; -         $i++; the     } +Zip_close ($resource); A     return $data; the}
PHP Unzip zip file