note 78940 modified in ref.zip by danbrown

From: Date: Sun, 25 Oct 2009 13:09:31 +0000
Subject: note 78940 modified in ref.zip by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162054@lists.php.net to get a copy of this message
With this extension you can Add dirs with files with the ZipArchive Object <?php /** * FlxZipArchive, Extends ZipArchiv. * Add Dirs with Files and Subdirs. * * <code> * $archive = new FlxZipArchive; * // ..... * $archive->addDir( 'test/blub', 'blub' ); * </code> */ class FlxZipArchive extends ZipArchive { /** * Add a Dir with Files and Subdirs to the archive * * @param string $location Real Location * @param string $name Name in Archive * @author Nicolas Heimann * @access private **/ 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 == '..') continue; // Rekursiv, If dir: FlxZipArchive::addDir(), else ::File(); $do = (filetype() == 'dir') ? 'addDir' : 'addFile'; $this->$do($location . $file, $name . $file); } } // EO addDirDo(); } ?> --was-- With this extension you can Add dirs with files with the ZipArchive Object /** * FlxZipArchive, Extends ZipArchiv. * Add Dirs with Files and Subdirs. * * <code> * $archive = new FlxZipArchive; * // ..... * $archive->addDir( 'test/blub', 'blub' ); * </code> */ class FlxZipArchive extends ZipArchive { /** * Add a Dir with Files and Subdirs to the archive * * @param string $location Real Location * @param string $name Name in Archive * @author Nicolas Heimann * @access private **/ 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 == '..') continue; // Rekursiv, If dir: FlxZipArchive::addDir(), else ::File(); $do = (filetype() == 'dir') ? 'addDir' : 'addFile'; $this->$do($location . $file, $name . $file); } } // EO addDirDo(); } http://php.net/manual/en/ref.zip.php

« previous php.notes (#162054) next »