34 lines
951 B
PHP
34 lines
951 B
PHP
<?php
|
||
|
||
/**
|
||
* Расширение класса ZipArchive с возможность архивирования директории
|
||
*/
|
||
class ZipFile extends ZipArchive
|
||
{
|
||
private function addDirDo($location, $name)
|
||
{
|
||
assert(is_string($location) && is_string($name));
|
||
|
||
$name .= '/';
|
||
$location .= '/';
|
||
|
||
// Read all Files in Dir
|
||
$dir = opendir($location);
|
||
while (($file = readdir($dir)) !== false)
|
||
{
|
||
if ($file === '.' || $file === '..') continue;
|
||
|
||
// Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
|
||
$call = (is_dir($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);
|
||
}
|
||
}
|