<?php
class zipmaker
{
protected $archive;
protected $zip;
protected $path;
function __construct($path)
{
if (!class_exists('ZIPArchive')) {
throw new Exception(
'Zip extension is not available');
}
$this->path = $path;
}
function addFile($path, $fileOrStream)
{
if (is_resource($fileOrStream)) {
$this->zip->addFromString($path, stream_get_contents($fileOrStream));
} else {
$this->zip->addFromString($path, $fileOrStream);
}
}
function init()
{
$this->zip = new ZipArchive;
if (true !== $this->zip->open($this->path, ZIPARCHIVE::CREATE)) {
throw new Exception(
'Cannot open ZIP archive ' . $this->path
);
}
}
function mkdir($dir)
{
$this->zip->addEmptyDir($dir);
}
function close()
{
$this->zip->close();
}
}