note 98619 deleted from function.ziparchive-addemptydir by danbrown

From: Date: Sat, 26 Jun 2010 23:58:10 +0000
Subject: note 98619 deleted from function.ziparchive-addemptydir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170499@lists.php.net to get a copy of this message
Note Submitter: hunter666 at abv dot bg ---- Add folder and sub-directories to zip archive. <?php $archive_name = "archive.zip"; // местонахождението и името на zip файла $archive_folder = "folder"; // папката, която ще бъде архивирана $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!'; } ?>

« previous php.notes (#170499) next »