FlySystem.rst 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. Usage with FlySystem
  2. ===============
  3. For saving or uploading the generated zip, you can use the
  4. `Flysystem <https://flysystem.thephpleague.com>`_ package, and its many
  5. adapters.
  6. For that you will need to provide another stream than the ``php://output``
  7. default one, and pass it to Flysystem ``putStream`` method.
  8. .. code-block:: php
  9. // Open Stream only once for read and write since it's a memory stream and
  10. // the content is lost when closing the stream / opening another one
  11. $tempStream = fopen('php://memory', 'w+');
  12. // Init Options
  13. $zipStreamOptions = new Archive();
  14. $zipStreamOptions->setOutputStream($tempStream);
  15. // Create Zip Archive
  16. $zipStream = new ZipStream('test.zip', $zipStreamOptions);
  17. $zipStream->addFile('test.txt', 'text');
  18. $zipStream->finish();
  19. // Store File (see Flysystem documentation, and all its framework integration)
  20. $adapter = new Local(__DIR__.'/path/to/folder'); // Can be any adapter (AWS, Google, Ftp, etc.)
  21. $filesystem = new Filesystem($adapter);
  22. $filesystem->putStream('test.zip', $tempStream)
  23. // Close Stream
  24. fclose($tempStream);