-
-
Save pareshsojitra/4ebd0f55cd15d71df85e093dd63f4738 to your computer and use it in GitHub Desktop.
Revisions
-
ninadsp revised this gist
Jul 30, 2013 . 2 changed files with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <? /** * FlxZipArchive, Extends ZipArchiv. * Add Dirs with Files and Subdirs. @@ -48,4 +49,5 @@ private function addDirDo($location, $name) { $this->$do($location . $file, $name . $file); } } // EO addDirDo(); } ?> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php //Don't forget to remove the trailing slash $the_folder = '/path/to/folder/to/be/zipped'; @@ -12,4 +13,5 @@ $za->close(); } else echo 'Could not create a zip archive'; ?> -
ninadsp created this gist
Jul 28, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ /** * 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( $location . $file) == 'dir') ? 'addDir' : 'addFile'; $this->$do($location . $file, $name . $file); } } // EO addDirDo(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ //Don't forget to remove the trailing slash $the_folder = '/path/to/folder/to/be/zipped'; $zip_file_name = '/path/to/zip/archive.zip'; $za = new FlxZipArchive; $res = $za->open($zip_file_name, ZipArchive::CREATE); if($res === TRUE) { $za->addDir($the_folder, basename($the_folder)); $za->close(); } else echo 'Could not create a zip archive';