Cannot add directory
Adding a directory fails with (vendor\stechstudio\laravel-zipstream\src\Models\LocalFile.php:23):
fopen(/the/path/): failed to open stream: No such file or directory
I'm trying to add a directory without adding any files in it, i.e.
$zip->add('/path/to/dir/', 'dir/');
I just want an empty directory (no files, unless I later add files into it via add()). The idea is something like this:
$zip = new Zip('archive.zip');
$zip->add('/path/to/dir/', 'dir/');
if ($something) $zip->add('/path/to/dir/fle.jpg', 'dir/file.jpg');
I want the dir to exist even if no conditions are met. There doesn't seem to be an obvious way to accomplish this.
Correct, there is no current support in this package for adding empty directories to a zip.
Correct, there is no current support in this package for adding empty directories to a zip.
Could it be added?
I don't think so. There is no option to add empty folders in the underlying ZipStream-PHP library that this package uses, and no plans to add it either.
$zip = new Zip('archive.zip'); $zip->add('/path/to/dir/', 'dir/'); if ($something) $zip->add('/path/to/dir/fle.jpg', 'dir/file.jpg');
how add directory like that: maybe this reference can be next update like this: https://github.com/zanysoft/laravel-zip
Skip that middle line, don't try to add the directory. Just $zip->add('/path/to/dir/fle.jpg', 'dir/file.jpg'); and it will create the zip directory for you.
I don't think so. There is no option to add empty folders in the underlying
ZipStream-PHPlibrary that this package uses, and no plans to add it either.
It looks like ZipStream-PHP has support for it, take a look at this issue https://github.com/maennchen/ZipStream-PHP/issues/78 .
Here is the docs https://maennchen.dev/ZipStream-PHP/classes/ZipStream-ZipStream.html#method_addDirectory
Honestly, i need to create blank directory to reflect the real view in the web where folders is empty. And if the user download the parent folder, it include the empty directory. Think like Google Drive, what if some user download a directory and they expect the empty folder in the zip downloaded, but there is not the empty folder? Seems wrong to me.
Hopefully you add a support for it.
I'm glad to see the underlying ZipStream-PHP library has added support. This seems reasonable now. I'm not sure when I'll have time to add this, and would welcome a pull request if someone wants to take a stab at it.