phplibrary/src/ZipFile.php

44 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Расширение класса ZipArchive с возможность архивирования директории
*/
namespace ctiso;
use ZipArchive;
class ZipFile extends ZipArchive
{
private $ignore = array('.', '..');
public function addIgnore($name)
{
$this->ignore [] = $name;
}
private function addDirDo($location, $name)
{
assert(is_string($location) && is_string($name));
$name .= '/';
$location .= '/';
$file = null;
// Read all Files in Dir
$dir = opendir($location);
while (($file = readdir($dir)) !== false)
{
if (in_array($file, $this->ignore)) continue;
// Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
$call = (is_dir($location . $file)) ? 'addDir' : 'addFile';
call_user_func(array($this, $call), $location . $file, $name . $file);
}
}
public function addDir($location, $name)
{
assert(is_string($location) && is_string($name));
$this->addEmptyDir($name);
$this->addDirDo($location, $name);
}
}