Reputation: 913
I have the next folder with files:
2147485934: {image.ai, image.jpg, image.psd}
And I want to create a new zip with thoses files:
<?
$zip = new ZipArchive;
$zip->open('newPack.zip', ZipArchive::CREATE);
foreach (glob("2147485934/*") as $file) {
$zip->addFile($file);
}
$zip->close();
?>
It works, but the new zip file have the same structure:
newPack.zip --> 2147485934: {image.ai, image.jpg, image.psd}
and I want to get the next structure inside my zip:
newPack.zip --> image.ai, image.jpg, image.psd //without folder 2147485934
Any help with this problem would be much appreciated
Upvotes: 0
Views: 1629
Reputation: 62
Try this:
$zip->addFile($file, basename($file));
The second argument defines the name of the file inside the archive. The code I added strips the directory name from the filename inside the archive.
Upvotes: 1
Reputation: 3396
Move to the selected folder with chdir:
<?
$zip = new ZipArchive;
$zip->open('newPack.zip', ZipArchive::CREATE);
chdir('2147485934')
foreach (glob("*") as $file) {
$zip->addFile($file);
}
$zip->close();
?>
Upvotes: 0