MuyuZip.php 873 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. class MuyuZip{
  3. public static function compresszip($zipnname,$path){
  4. $zip = new ZipArchive();
  5. if ($zip->open($zipnname, ZIPARCHIVE::CREATE) === true) {
  6. $files = self::listdir($path);
  7. if($files !== false){
  8. foreach($files as $p)
  9. {
  10. $zip->addFile($p,str_replace("./","",str_replace("\\","/",$p)));
  11. }
  12. $zip->close();
  13. return true;
  14. }else{
  15. return false;
  16. }
  17. }else{
  18. return false;
  19. }
  20. }
  21. public static function listdir($start_dir) {
  22. $files = array();
  23. if (is_dir($start_dir)) {
  24. $fh = opendir($start_dir);
  25. while (($file = readdir($fh)) !== false) {
  26. if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;
  27. $filepath = $start_dir . '/' . $file;
  28. if ( is_dir($filepath) )
  29. $files = array_merge($files, self::listdir($filepath));
  30. else
  31. array_push($files, $filepath);
  32. }
  33. closedir($fh);
  34. } else {
  35. $files = false;
  36. }
  37. return $files;
  38. }
  39. }