note 98619 deleted from function.ziparchive-addemptydir by danbrown
| From: | danbrown@php.net | 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!';
}
?>