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

Creating Zip File from Folder #28

Closed
Purus opened this issue Dec 2, 2013 · 4 comments
Closed

Creating Zip File from Folder #28

Purus opened this issue Dec 2, 2013 · 4 comments

Comments

@Purus
Copy link

Purus commented Dec 2, 2013

How would I zip an entire folder and make it available as a zip file? I have couple of views on the documents and I am not able to get any info on zipping the files.

Please let me know if I am missing any thing on this.

@frankdejonge
Copy link
Member

Although this is not an official feature of the package, it does make it super simple to implement yourself, like so:

$local = new Flysystem\FIlesystem(Flysystem\Adapter\Local(__DIR__.'/path/to/dir'));
$zip = new Flysystem\FIlesystem(Flysystem\Adapter\Zip(__DIR__.'/path/to/archive.zip'));

$contents = $local->listContents('', true);

foreach ($contents as $info) {
    if ($info['type'] === 'dir') {
        continue;
    }

    $zip->write($info['path'], $local->read($info['path']));
}

// This will trigger saving the zip.
$zip = null;

Now you'll have the archive zipped the local directory and stored at _DIR__.'/path/to/archive.zip'

@Purus
Copy link
Author

Purus commented Dec 2, 2013

Thanks again. I somehow figured this logic..

Hope you won't mind if I add this an feature to your Zip adapter as a new function..

@Purus Purus closed this as completed Dec 2, 2013
@frankdejonge
Copy link
Member

It's not something that will be included in the default zip adapter, this because it's not a feature that is cross adapter compatible.

@Purus
Copy link
Author

Purus commented Dec 2, 2013

Yeah. Got your point. Thanks.

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

2 participants