Back to index

php5  5.3.10
zipmaker.php.inc
Go to the documentation of this file.
00001 <?php
00002 // stolen from PEAR2_Pyrus_Developer_Creator_Zip by Greg Beaver, the original author, for use in unit tests
00003 class zipmaker
00004 {
00010     protected $archive;
00014     protected $zip;
00015     protected $path;
00016     function __construct($path)
00017     {
00018         if (!class_exists('ZIPArchive')) {
00019             throw new Exception(
00020                 'Zip extension is not available');
00021         }
00022         $this->path = $path;
00023     }
00024 
00030     function addFile($path, $fileOrStream)
00031     {
00032         if (is_resource($fileOrStream)) {
00033             $this->zip->addFromString($path, stream_get_contents($fileOrStream));
00034         } else {
00035             $this->zip->addFromString($path, $fileOrStream);
00036         }
00037     }
00038 
00042     function init()
00043     {
00044         $this->zip = new ZipArchive;
00045         if (true !== $this->zip->open($this->path, ZIPARCHIVE::CREATE)) {
00046             throw new Exception(
00047                 'Cannot open ZIP archive ' . $this->path
00048             );
00049         }
00050     }
00051 
00058     function mkdir($dir)
00059     {
00060         $this->zip->addEmptyDir($dir);
00061     }
00062 
00066     function close()
00067     {
00068         $this->zip->close();
00069     }
00070 }