I am currently using the following piece of code to ZIP the current folder:
<?php
$rootPath = realpath('./');
$zip = new ZipArchive();
$zip->open('archive.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
if (!$file->isDir())
{
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
?>
The ZIP file is created fine - however, I noticed that for some reason it fails to include one empty folder that is a subfolder of the current folder. All other files/folders are added to the archive, but the empty folder is completely omitted.
Would anyone be kind enough to point me as to why this is happening?
This is not a duplicate topic - I need to know why ZIP does not add any empty subfolders of the main folder I am zipping. They are empty, but I need them too.