<?php Need to open configuration Php_zip.dll Phpinfo (); Header ("Content-type:text/html;charset=utf-8"); function Get_zip_originalsize ($filename, $path) { First determine if the file you want to extract exists if (!file_exists ($filename)) { Die ("file $filename does not exist!") "); } $starttime = Explode (', microtime ()); Time to start decompression The file name and path are converted to the Windows system default gb2312 encoding, otherwise you will not be able to read the $filename = Iconv ("Utf-8", "gb2312", $filename); $path = Iconv ("Utf-8", "gb2312", $path); Open a compressed package $resource = Zip_open ($filename); $i = 1; Traversal read a file inside a compressed package while ($dir _resource = Zip_read ($resource)) { If you can open it, continue. if (Zip_entry_open ($resource, $dir _resource)) { Gets the name of the current project, which is the current file name in the ZIP package $file _name = $path. Zip_entry_name ($dir _resource); Split the Last "/", then intercept the path part with a string $file _path = substr ($file _name,0,strrpos ($file _name, "/")); If the path does not exist, a directory is created, and True indicates that you can create multilevel catalogs if (!is_dir ($file _path)) { mkdir ($file _path,0777,true); } Write file if it is not a directory if (!is_dir ($file _name)) { Read this file $file _size = zip_entry_filesize ($dir _resource); Maximum read 6M, if the file is too large, skip decompression, continue to the next if ($file _size< (1024*1024*6)) { $file _content = Zip_entry_read ($dir _resource, $file _size); File_put_contents ($file _name, $file _content); }else{www.111cn.net echo "<p>". $i + +. "This file has been skipped because the file is too large,->". Iconv ("gb2312", "Utf-8", $file _name). "</p>"; } } Closes the current Zip_entry_close ($dir _resource); } } Turn off compression packs Zip_close ($resource); $endtime = Explode (', microtime ()); Time the decompression ended $thistime = $endtime [0]+ $endtime [1]-($starttime [0]+ $starttime [1]); $thistime = Round ($thistime, 3); Keep 3 as Decimal echo "<p> decompression completed! , this decompression cost: $thistime seconds. </p> "; } $size = get_zip_originalsize (' 20131101.zip ', ' 1 Degary/'); ?> |