summaryrefslogtreecommitdiffstats
path: root/vendor/maennchen/zipstream-php/guides/FlySystem.rst
blob: 0243f2482097835543be03036840ece2bf9a9ecb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Usage with FlySystem
===============

For saving or uploading the generated zip, you can use the
`Flysystem <https://flysystem.thephpleague.com>`_ package, and its many
adapters.

For that you will need to provide another stream than the ``php://output``
default one, and pass it to Flysystem ``putStream`` method.

.. code-block:: php

    // Open Stream only once for read and write since it's a memory stream and
    // the content is lost when closing the stream / opening another one
    $tempStream = fopen('php://memory', 'w+');

    // Init Options
    $zipStreamOptions = new Archive();
    $zipStreamOptions->setOutputStream($tempStream);

    // Create Zip Archive
    $zipStream = new ZipStream('test.zip', $zipStreamOptions);
    $zipStream->addFile('test.txt', 'text');
    $zipStream->finish();

    // Store File (see Flysystem documentation, and all its framework integration)
    $adapter = new Local(__DIR__.'/path/to/folder'); // Can be any adapter (AWS, Google, Ftp, etc.)
    $filesystem = new Filesystem($adapter);

    $filesystem->putStream('test.zip', $tempStream)

    // Close Stream
    fclose($tempStream);