Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add directory #62

Open
Ancyker opened this issue Feb 14, 2022 · 8 comments
Open

Cannot add directory #62

Ancyker opened this issue Feb 14, 2022 · 8 comments

Comments

@Ancyker
Copy link

Ancyker commented Feb 14, 2022

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.

@jszobody
Copy link
Member

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

@Ancyker
Copy link
Author

Ancyker commented Feb 14, 2022

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

Could it be added?

@jszobody
Copy link
Member

jszobody commented Feb 14, 2022

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.

@ozonerik
Copy link

$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

@jszobody
Copy link
Member

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.

@kiraware
Copy link

kiraware commented Nov 1, 2024

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 maennchen/ZipStream-PHP#78 .

Here is the docs https://maennchen.dev/ZipStream-PHP/classes/ZipStream-ZipStream.html#method_addDirectory

@kiraware
Copy link

kiraware commented Nov 1, 2024

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.

@jszobody jszobody reopened this Nov 5, 2024
@jszobody
Copy link
Member

jszobody commented Nov 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants