index.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. If ``composer install`` yields the following error, your installation is missing
  24. the `mbstring extension <https://www.php.net/manual/en/book.mbstring.php>`_,
  25. either `install it <https://www.php.net/manual/en/mbstring.installation.php>`_
  26. or run the follwoing command:
  27. .. code-block::
  28. Your requirements could not be resolved to an installable set of packages.
  29. Problem 1
  30. - Root composer.json requires PHP extension ext-mbstring * but it is
  31. missing from your system. Install or enable PHP's mbstrings extension.
  32. .. code-block:: sh
  33. composer require symfony/polyfill-mbstring
  34. Usage Intro
  35. ---------------
  36. Here's a simple example:
  37. .. code-block:: php
  38. // Autoload the dependencies
  39. require 'vendor/autoload.php';
  40. // enable output of HTTP headers
  41. $options = new ZipStream\Option\Archive();
  42. $options->setSendHttpHeaders(true);
  43. // create a new zipstream object
  44. $zip = new ZipStream\ZipStream('example.zip', $options);
  45. // create a file named 'hello.txt'
  46. $zip->addFile('hello.txt', 'This is the contents of hello.txt');
  47. // add a file named 'some_image.jpg' from a local file 'path/to/image.jpg'
  48. $zip->addFileFromPath('some_image.jpg', 'path/to/image.jpg');
  49. // add a file named 'goodbye.txt' from an open stream resource
  50. $fp = tmpfile();
  51. fwrite($fp, 'The quick brown fox jumped over the lazy dog.');
  52. rewind($fp);
  53. $zip->addFileFromStream('goodbye.txt', $fp);
  54. fclose($fp);
  55. // finish the zip stream
  56. $zip->finish();
  57. You can also add comments, modify file timestamps, and customize (or
  58. disable) the HTTP headers. It is also possible to specify the storage method
  59. when adding files, the current default storage method is ``DEFLATE``
  60. i.e files are stored with Compression mode 0x08.
  61. Known Issues
  62. ---------------
  63. The native Mac OS archive extraction tool prior to macOS 10.15 might not open
  64. archives in some conditions. A workaround is to disable the Zip64 feature with
  65. the option ``enableZip64: false``. This limits the archive to 4 Gb and 64k files
  66. but will allow users on macOS 10.14 and below to open them without issue.
  67. See `#116 <https://github.com/maennchen/ZipStream-PHP/issues/146>`_.
  68. The linux ``unzip`` utility might not handle properly unicode characters.
  69. It is recommended to extract with another tool like
  70. `7-zip <https://www.7-zip.org/>`_.
  71. See `#146 <https://github.com/maennchen/ZipStream-PHP/issues/146>`_.
  72. It is the responsability of the client code to make sure that files are not
  73. saved with the same path, as it is not possible for the library to figure it out
  74. while streaming a zip.
  75. See `#154 <https://github.com/maennchen/ZipStream-PHP/issues/154>`_.