note 98620 added to function.ziparchive-addemptydir

From: Date: Sat, 26 Jun 2010 20:39:19 +0000
Subject: note 98620 added to function.ziparchive-addemptydir
Groups: php.notes 
Request: Send a blank email to php-notes+get-170493@lists.php.net to get a copy of this message
Add folder and sub-directories to zip archive. <?php $archive_name = "archive.zip"; // name of zip file $archive_folder = "folder"; // the folder which you archivate $zip = new ZipArchive; if ($zip -> open($archive_name, ZipArchive::CREATE) === TRUE) { $dir = preg_replace('/[\/]{2,}/', '/', $archive_folder."/"); $dirs = array($dir); while (count($dirs)) { $dir = current($dirs); $zip -> addEmptyDir($dir); $dh = opendir($dir); while($file = readdir($dh)) { if ($file != '.' && $file != '..') { if (is_file($file)) $zip -> addFile($dir.$file, $dir.$file); elseif (is_dir($file)) $dirs[] = $dir.$file."/"; } } closedir($dh); array_shift($dirs); } $zip -> close(); echo 'Archiving is sucessful!'; } else { echo 'Error, can\'t create a zip file!'; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 85.130.90.65 ---- Manual Page -- http://www.php.net/manual/en/function.ziparchive-addemptydir.php Edit -- https://master.php.net/note/edit/98620 Del: integrated -- https://master.php.net/note/delete/98620/integrated Del: useless -- https://master.php.net/note/delete/98620/useless Del: bad code -- https://master.php.net/note/delete/98620/bad+code Del: spam -- https://master.php.net/note/delete/98620/spam Del: non-english -- https://master.php.net/note/delete/98620/non-english Del: in docs -- https://master.php.net/note/delete/98620/in+docs Del: other reasons-- https://master.php.net/note/delete/98620 Reject -- https://master.php.net/note/reject/98620 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170493) next »