I'm using the ZipArchive class in PHP for the first time, and I'm having a bit of trouble. All I'm trying to do is iterate through the files in the ZIP archive, and it all works, except it doesn't seem there's any way to get subdirectory names inside the ZIP file, and I need that information. If there are files inside the subdirectoy, I suppose I could parse the directory names out of the file names, but if there are empty directories, they're completely lost.
For instance, if I have this directory tree in a ZIP:
root_folder
root_folder -> test_file.ext
root_folder -> empty_dir
Now I try to read that ZIP file's entries into memory like this in PHP:
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') == TRUE) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
echo $filename."<br />";
}
$zip->close();
}
?>
If I do this, then root_folder\test_file.ext
is found correctly, but root_folder\empty_dir
is just lost entirely.
So how do I use the ZipArchive class to find all the files and directories, including empty ones inside the archive?