Home >Backend Development >PHP Tutorial >PHP calls nginx's mod_zip module to package ZIP files_PHP tutorial
php itself has a zip module that can produce zip files. But this zip module can only use local files for packaging. If the files that need to be packaged and output come from the network, you must first save the temporary files. This is a problem when there are many files or the files are large. In addition, using PHP to output large packaged files will take up a lot of time in the PHP process and affect concurrency capabilities.
nginx has a third-party module, mod_zip. You can also export zip packages. It is somewhat similar to X-Accel-Redirect. It only needs php to output the path of the corresponding file and other information, and then give a special response header.
The response header used by the nginx zip module is X-Archive-Files: zip . With this response header added, the nginx zip module will process the response body and complete the packaging output.
For example:
$crc32 is the hexadecimal file crc32 value. It can also be omitted and replaced with "-". However, in this way, it is impossible to use Range to download in chunks and resume the download from a breakpoint.
$size is the decimal integer of the file size.
$url is the source address to be packaged. If you want to package a local file, you can first create an internal path in nginx.
$path is the path in the zip package.
However, this cannot create an empty directory. On the one hand, the zip format did not define an empty directory from the beginning. Later standards and software implemented this by adding a 0-size file ending with /. At this time, you need to first create an internal 0-size file in nginx, such as located at /_0. Then output