laravel-zipstream icon indicating copy to clipboard operation
laravel-zipstream copied to clipboard

Cannot add directory

Open Ancyker opened this issue 3 years ago • 8 comments

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.

Ancyker avatar Feb 14 '22 21:02 Ancyker

Correct, there is no current support in this package for adding empty directories to a zip.

jszobody avatar Feb 14 '22 21:02 jszobody

Correct, there is no current support in this package for adding empty directories to a zip.

Could it be added?

Ancyker avatar Feb 14 '22 21:02 Ancyker

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.

jszobody avatar Feb 14 '22 21:02 jszobody

$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

ozonerik avatar Feb 20 '22 23:02 ozonerik

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.

jszobody avatar Feb 20 '22 23:02 jszobody

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.

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

kiraware avatar Nov 01 '24 04:11 kiraware

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.

kiraware avatar Nov 01 '24 04:11 kiraware

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.

jszobody avatar Nov 05 '24 15:11 jszobody