44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?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);
|
||
}
|
||
}
|