So let's say you have a ZipFile: test.zip
Structure:
- file1.txt
- file1.txt
- - dir1/
- - - file3.txt
- - - file4.txt
- - dir2/
- - - file5.txt
- - - file6.txt
To keep ZIP structure you could do:
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
$zip->extractTo('./test', array('file1.txt', 'file2.txt'));
$zip->extractTo('./test', array('dir1/file3.txt', 'dir1/file4.txt'));
$zip->extractTo('./test', array('dir2/file5.txt', 'dir2/file6.txt'));
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
That's the same as doing
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
$zip->extractTo('./test');
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>
But if you have a test.zip file with this Structure:
- file1.txt
- file1.txt
- file3.txt
- file4.txt
- file5.txt
- file6.txt
And you want to get output structured as before, you could do this:
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
$zip->extractTo('./test/', array('file1.txt', 'file2.txt'));
$zip->extractTo('./test/dir1', array('file3.txt', 'file4.txt'));
$zip->extractTo('./test/dir2', array('file5.txt', 'file6.txt'));
$zip->close();
echo 'ok';
} else {
echo 'failed';
}
?>