Php: use *** to create a zip package * @ paramarray $ arr to compress partial paths and file names, such as array (* fileupload1.php, * fileupload20111.jpg ,*) ** @ returnstring: part of the path and file name of the compressed package. php uses zip.
/***** Create a compressed package * @ param array $ arr partial paths and file names to be compressed, such as array (* '/file/upload/1. php ', *'/file/upload/2011/1 .jpg ', *) ** @ return part of the path and file name of the string compressed package, for example,/file/uplaod/zip/123.zip */public static function zip ($ arr) {// first, I create a directory $ save_path = '/file/upload/zip '. dat: getHourPath (); $ path = APPLICATION_PATH. '/destoon '. $ save_path; Sys: createDir ($ path); $ zipname = strval (time ()). mt_rand (100000,999 9 99 ). '.zip '; $ zip_fullname = $ path. '/'. $ zipname; $ zip_obj = new ZipArchive (); if ($ zip_obj-> open ($ zip_fullname, ZIPARCHIVE: CREATE )! = True) {return false;} foreach ($ arr as $ value) {// $ zip-> addFile ($ path, mb_convert_encoding (basename ($ path ), 'gbk', 'utf-8'); $ zip_obj-> addFile (APPLICATION_PATH. '/destoon '. $ value, basename ($ value);} $ zip_obj-> close (); return $ save_path. '/'. $ zipname;}/*** decompress ** @ param string $ zipname part of the path and file name of the compressed package, like '/file/upload/1.zip' * @ param string $ path: the full path of the decompressed folder ** @ return array Array, partial path and file name, such as array (* '/file/1. php ', *'/file/12.png ', *) */public static function unzip ($ zipname, $ path = '') {if (! $ Path) {$ path = '/file/tempzip_folder /'. strval (time ()). mt_rand (100000,999 999); $ newpath = APPLICATION_PATH. '/destoon '. $ path;} else {$ newpath = $ path; $ path = preg_replace ('# ^. +/destoon (. +) $ # ',' $ 1', $ newpath);} Sys: createDir ($ newpath); $ filename = APPLICATION_PATH. '/destoon '. $ zipname; // Extract $ zip = new ZipArchive (); $ arr = array (); if ($ zip-> open ($ filename) === true) {$ zip-> e Xtraceid ($ newpath); $ zip-> close (); $ temp = scandir ($ newpath); foreach ($ temp as $ value) {if ($ value! = '.' & $ Value! = '..') {$ Arr [] = $ path. '/'. basename ($ value) ;}} return $ arr ;}