1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- class MuyuZip{
-
- public static function compresszip($zipnname,$path){
- $zip = new ZipArchive();
- if ($zip->open($zipnname, ZIPARCHIVE::CREATE) === true) {
- $files = self::listdir($path);
- if($files !== false){
- foreach($files as $p)
- {
- $zip->addFile($p,str_replace("./","",str_replace("\\","/",$p)));
- }
- $zip->close();
- return true;
- }else{
- return false;
- }
- }else{
- return false;
- }
- }
- public static function listdir($start_dir) {
- $files = array();
- if (is_dir($start_dir)) {
- $fh = opendir($start_dir);
- while (($file = readdir($fh)) !== false) {
- if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;
- $filepath = $start_dir . '/' . $file;
- if ( is_dir($filepath) )
- $files = array_merge($files, self::listdir($filepath));
- else
- array_push($files, $filepath);
- }
- closedir($fh);
- } else {
- $files = false;
- }
- return $files;
- }
- }
|