note 86188 added to function.ziparchive-addemptydir

From: Date: Tue, 07 Oct 2008 12:26:43 +0000
Subject: note 86188 added to function.ziparchive-addemptydir
Groups: php.notes 
Request: Send a blank email to php-notes+get-145120@lists.php.net to get a copy of this message
I've brought a little modification to dayjo's code, so it wouldn't re-create the whole structure of your working drive in the zip file: <?php // Function to recursively add a directory, // sub-directories and files to a zip archive function addFolderToZip($dir, $zipArchive, $zipdir = ''){ if (is_dir($dir)) { if ($dh = opendir($dir)) { //Add the directory $zipArchive->addEmptyDir($dir); // Loop through all the files while (($file = readdir($dh)) !== false) { //If it's a folder, run the function again! if(!is_file($dir . $file)){ // Skip parent and root directories if( ($file !== ".") && ($file !== "..")){ addFolderToZip($dir . $file . "/", $zipArchive, $zipdir . $file . "/"); } }else{ // Add the files $zipArchive->addFile($dir . $file, $zipdir . $file); } } } } } ?> If you don't specify the third parameter (zipdir), the directory you're adding will be added at the root of the zip file. D.Jann ---- Server IP: 89.31.146.176 Probable Submitter: 212.74.185.158 ---- Manual Page -- http://www.php.net/manual/en/function.ziparchive-addemptydir.php Edit -- https://master.php.net/note/edit/86188 Del: integrated -- https://master.php.net/note/delete/86188/integrated Del: useless -- https://master.php.net/note/delete/86188/useless Del: bad code -- https://master.php.net/note/delete/86188/bad+code Del: spam -- https://master.php.net/note/delete/86188/spam Del: non-english -- https://master.php.net/note/delete/86188/non-english Del: in docs -- https://master.php.net/note/delete/86188/in+docs Del: other reasons-- https://master.php.net/note/delete/86188 Reject -- https://master.php.net/note/reject/86188 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145120) next »