Closed dotriz closed 1 year ago
Hello @dotriz,
You can do like that to create an empty directory (with version 1.0.0-alpha):
$zip->addFile('directory/', '');
@NicolasCARPi Any plan to add this support in previous versions?
It doesn't work in previous versions?
@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.
@NicolasCARPi that's correct, it doesn't work on previous versions.
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.
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
@maennchen Help wanted, means a pull request for it would be merged? 🙂
@christian-kolb a PR is very welcome 🙂
@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 🙂
@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...
Hello, what's about this feature ?
@bastien70 A PR would be welcome.
I don't have the capacity to do that kind of PR sorry.
@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.
@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).
Tracked in #224
@maennchen any new about this feature ?
@ahmed-bhs This feature is part of the current beta release.
Hey @maennchen 3.0.0@beta ? Does there any documentation behind the feature?
@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.
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.