note 84998 deleted from ref.zip by bjori
| From: | bjori@php.net | Date: | Sat, 09 Aug 2008 17:15:35 +0000 |
| Subject: | note 84998 deleted from ref.zip by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143323@lists.php.net to get a copy of this message | ||
Note Submitter: at dot shamad at gmail dot com
Reason: bad code
----
nheimann at gmx dot net make some mistakes...
Here's a more simple extended class to add a whole directory recursively, keeping the same
structure. It uses SPL.
<?php
class FlxZipArchive extends ZipArchive {
public function addDir($location, $name) {
$this->addEmptyDir($name);
$this->addDirDo($location, $name);
} // EO addDir;
/**
* Add Files & Dirs to archive.
*
* @param string $location Real Location
* @param string $name Name in Archive
* @author Nicolas Heimann
* @access private
**/
private function addDirDo($location, $name) {
$name .= '/';
$location .= '/';
// Read all Files in Dir
$dir = opendir ($location);
while ($file = readdir($dir))
{
if ($file != '.' && $file != '..') {
// Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
$do = (filetype($location.$file) == 'dir') ? 'addDir' :
'addFile';
$this->$do($location . $file, $name . $file);
}
}
} // EO addDirDo();
}
$archive = new FlxZipArchive;
$archive->open('D:/test.zip', ZIPARCHIVE::CREATE);
$archive->addDir( 'D:/test', 'newdir');
$archive->close('D:/test.zip');
?>