Вход Регистрация
* Balltazor

создание zip архивов

  1. <?php
  2.  
  3. //Zipper.class.php//
  4.  
  5. class Zipper {
  6. private $_files = array(),
  7. $_zip;
  8.  
  9. public function __construct() { // вызываем класс архиватора
  10. $this->_zip = new ZipArchive;
  11. }
  12.  
  13. public function add($input) {
  14. if (is_array($input)) { // если добавляем несколько файлов
  15. $this->_files = array_merge($this->_files, $input);
  16. } else { // добавление одного файла
  17. $this->_files[] = $input;
  18. }
  19. }
  20.  
  21. public function store($location = null) {
  22. if (count($this->_files) && $location) { // если есть файлы, и правильный путь, где будет создан новый архив
  23. foreach ($this->_files as $index => $file) { // удаляем файлы с не верными путями
  24. if (!file_exists($file)) {
  25. unset($this->_files[$index]);
  26. }
  27. }
  28.  
  29. if ($this->_zip->open($location, file_exists($location) ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE)) { // создаем архив
  30. foreach ($this->_files as $file) { // добаляем в архив файлы
  31. $this->_zip->addFile($file, $file);
  32. }
  33.  
  34. $this->_zip->close(); // закрывем архив
  35. }
  36. }
  37. }
  38. }
  39. ?>
  40.  
  41. Пример использования
  42. $zip = new Zipper;
  43.  
  44. $zip->add(array('files/1.txt', 'files/2.txt', 'files/3.txt', 'files/4.txt')); // добавление файлов в архив
  45.  
  46. $zip->store('files/archiv.zip'); // создание архива
» Описание: мини-класс для работы с zip архивами
» Время добавления: 22 Июня 2014 в 14:55
» Посмотров: 1125
» textarea
» Рейтинг: [+0 | -0]
Комментарии [0]
Онлайн: 1
Реклама