PHP Unzip zip file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.