index.rst 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ZipStream PHP
  2. =============
  3. A fast and simple streaming zip file downloader for PHP. Using this library will
  4. save you from having to write the Zip to disk. You can directly send it to the
  5. user, which is much faster. It can work with S3 buckets or any PSR7 Stream.
  6. .. toctree::
  7. index
  8. Symfony
  9. Options
  10. StreamOutput
  11. FlySystem
  12. PSR7Streams
  13. Nginx
  14. Varnish
  15. ContentLength
  16. Installation
  17. ---------------
  18. Simply add a dependency on ``maennchen/zipstream-php`` to your project's
  19. ``composer.json`` file if you use Composer to manage the dependencies of your
  20. project. Use following command to add the package to your project's dependencies:
  21. .. code-block:: sh
  22. composer require maennchen/zipstream-php
  23. Usage Intro
  24. ---------------
  25. Here's a simple example:
  26. .. code-block:: php
  27. // Autoload the dependencies
  28. require 'vendor/autoload.php';
  29. // enable output of HTTP headers
  30. $options = new ZipStream\Option\Archive();
  31. $options->setSendHttpHeaders(true);
  32. // create a new zipstream object
  33. $zip = new ZipStream\ZipStream('example.zip', $options);
  34. // create a file named 'hello.txt'
  35. $zip->addFile('hello.txt', 'This is the contents of hello.txt');
  36. // add a file named 'some_image.jpg' from a local file 'path/to/image.jpg'
  37. $zip->addFileFromPath('some_image.jpg', 'path/to/image.jpg');
  38. // add a file named 'goodbye.txt' from an open stream resource
  39. $fp = tmpfile();
  40. fwrite($fp, 'The quick brown fox jumped over the lazy dog.');
  41. rewind($fp);
  42. $zip->addFileFromStream('goodbye.txt', $fp);
  43. fclose($fp);
  44. // finish the zip stream
  45. $zip->finish();
  46. You can also add comments, modify file timestamps, and customize (or
  47. disable) the HTTP headers. It is also possible to specify the storage method
  48. when adding files, the current default storage method is ``DEFLATE``
  49. i.e files are stored with Compression mode 0x08.
  50. Known Issues
  51. ---------------
  52. The native Mac OS archive extraction tool prior to macOS 10.15 might not open
  53. archives in some conditions. A workaround is to disable the Zip64 feature with
  54. the option ``enableZip64: false``. This limits the archive to 4 Gb and 64k files
  55. but will allow users on macOS 10.14 and below to open them without issue.
  56. See `#116 <https://github.com/maennchen/ZipStream-PHP/issues/146>`_.
  57. The linux ``unzip`` utility might not handle properly unicode characters.
  58. It is recommended to extract with another tool like
  59. `7-zip <https://www.7-zip.org/>`_.
  60. See `#146 <https://github.com/maennchen/ZipStream-PHP/issues/146>`_.
  61. It is the responsability of the client code to make sure that files are not
  62. saved with the same path, as it is not possible for the library to figure it out
  63. while streaming a zip.
  64. See `#154 <https://github.com/maennchen/ZipStream-PHP/issues/154>`_.