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

Create Directories #78

Closed
dotriz opened this issue Jul 19, 2018 · 21 comments · Fixed by #224
Closed

Create Directories #78

dotriz opened this issue Jul 19, 2018 · 21 comments · Fixed by #224
Assignees
Milestone

Comments

@dotriz
Copy link

dotriz commented Jul 19, 2018

I know how we can add files in folders and sub-folders in a zip. But is it possible to add blank folders?

I want to allow users to download their data in zip and want to match exactly same structure as they have on web, so creating lank folders is important.

@NicolasCARPi
Copy link
Sponsor Collaborator

NicolasCARPi commented Jul 30, 2018

Hello @dotriz,

You can do like that to create an empty directory (with version 1.0.0-alpha):

$zip->addFile('directory/', '');

@dotriz
Copy link
Author

dotriz commented Aug 8, 2018

@NicolasCARPi Any plan to add this support in previous versions?

@NicolasCARPi
Copy link
Sponsor Collaborator

It doesn't work in previous versions?

@maennchen
Copy link
Owner

@NicolasCARPi We should probably add a new function createDirectory that does this. This seems like a hack to me.

I would add the function to the v1 versions only.

@dotriz
Copy link
Author

dotriz commented Sep 13, 2018

@NicolasCARPi that's correct, it doesn't work on previous versions.

@NicolasCARPi NicolasCARPi reopened this Nov 13, 2018
@maennchen maennchen changed the title How can we create empty directories in zip? Create Directories Apr 18, 2019
@claytron5000
Copy link

I came here looking for this. I basically want to replace the PHP standard ZipArchive with this so that I can build and stream directly to s3. Our current implementation using ZipArchive uses the addEmptyDir.

I don't know if this is too ambitious, but something like a drop-in replacement for ZipArchive would be awesome. Maybe this should be a different issue.

https://www.php.net/manual/en/class.ziparchive.php

@walkingCommiter
Copy link

I have faced the same issue creating empty folders fails except if using what @NicolasCARPi suggested:

$zip->addFile($directory . DIRECTORY_SEPARATOR, '');

However, testing the download of a zipStream causes unit test failure since it counts empty folders created this way as a file:

$zip = new ZipArchive();
$zip->open($tempName); // open the downloaded stream
self::assertEquals($expectedFilesCount, $zip->count); // count is incorrect -- it counts folders as file

this counts extra for each folder which is totally wrong also happens for $zip

@christian-kolb
Copy link

@maennchen Help wanted, means a pull request for it would be merged? 🙂

@maennchen
Copy link
Owner

@christian-kolb a PR is very welcome 🙂

@christian-kolb
Copy link

christian-kolb commented Jun 10, 2021

@maennchen I started and saw pretty quickly that I severely underestimated the complexity of this library and what is needed to make this change. The whole directory construct doesn't seem to exist in the package yet.
My approach would be to create a Directory class according to the structure of the File class. But I'm not sure if the concepts match here. A directory doesn't have a content but is more of a marker. I'm pretty much lost as soon as it comes to the headers and the V... format. Can you point me to relevant documentation? Then I would try to pickup from there 🙂

@maennchen
Copy link
Owner

@christian-kolb Yeah, it's not that approachable.

For every change, I also have to read the specifications.

https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

Unfortunately, I also do not know about resources that are a lot better...

@bastien70
Copy link

Hello, what's about this feature ?

@maennchen
Copy link
Owner

@bastien70 A PR would be welcome.

@bastien70
Copy link

I don't have the capacity to do that kind of PR sorry.

@maennchen
Copy link
Owner

@bastien70 And I do not have the time. If this is important to anyone, please open a PR. Otherwise there will be no solution to this anytime soon.

@walkingCommiter
Copy link

walkingCommiter commented Jan 6, 2022

@bastien70 If it is okay for your customers I would suggest a simple solution to just putting an empty file in all empty folders by default to keep the structure (kind of like how .gitignore works for git folders) and just waiting for maintainers to see what we can do. (Also check last comment of me maybe it fails on unit test but works on runtime).

@maennchen maennchen added this to the v3.0.0 milestone Nov 25, 2022
@maennchen maennchen self-assigned this Nov 25, 2022
@maennchen maennchen mentioned this issue Nov 25, 2022
16 tasks
@maennchen
Copy link
Owner

Tracked in #224

@ahmed-bhs
Copy link

@maennchen any new about this feature ?

@maennchen
Copy link
Owner

@ahmed-bhs This feature is part of the current beta release.

@ahmed-bhs
Copy link

Hey @maennchen 3.0.0@beta ? Does there any documentation behind the feature?

@maennchen
Copy link
Owner

@ahmed-bhs The docs are not published right now.

You can checkout the project and generate the docs. (composer run docs:generate)

Otherwise everything is documented in the code comments.

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

Successfully merging a pull request may close this issue.

8 participants