note 84998 added to ref.zip
| From: | at dot shamad at gmail dot com | Date: | Sat, 09 Aug 2008 15:04:02 +0000 |
| Subject: | note 84998 added to ref.zip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143321@lists.php.net to get a copy of this message | ||
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');
?>
----
Server IP: 195.54.192.44
Probable Submitter: 127.0.0.1
----
Manual Page -- http://www.php.net/manual/en/ref.zip.php
Edit -- https://master.php.net/note/edit/84998
Del: integrated -- https://master.php.net/note/delete/84998/integrated
Del: useless -- https://master.php.net/note/delete/84998/useless
Del: bad code -- https://master.php.net/note/delete/84998/bad+code
Del: spam -- https://master.php.net/note/delete/84998/spam
Del: non-english -- https://master.php.net/note/delete/84998/non-english
Del: in docs -- https://master.php.net/note/delete/84998/in+docs
Del: other reasons-- https://master.php.net/note/delete/84998
Reject -- https://master.php.net/note/reject/84998
Search -- https://master.php.net/manage/user-notes.php