PHP Call nginx Mod_zip Module Package zip file _php Tutorial

Source: Internet
Author: User
PHP itself has a zip module that can produce zip files. However, this zip module can only be packaged using local files. If you need to package output files from the network, you have to save the temporary files first. It is a cup of paper when the number of documents is large or the file is big. In addition, PHP to output a large package of files will occupy the PHP process a lot of time, affecting the concurrency capability.

Nginx has a third-party module, Mod_zip. You can also export a zip package. And x-accel-redirect a bit similar, only need PHP output the path of the corresponding file, and then give a special response to the header.

The response header used by the Nginx Zip module is x-archive-files:zip. With this response header, the Nginx Zip module will process the response body and complete the packaged output.

Like what:
Copy the Code code as follows:
printf ("%s%d%s%s\n", $CRC, $size, $url, $path);
Output the files you want to package.

$CRC 32 is a 16-binary file CRC32 value. can also not provide, with "-" instead. However, this will not be able to download with the Range block, the breakpoint continues to pass.
$size is a decimal integer of the file size.
$url is the source address to package. If you want to package a local file, you can first make a internal path in Nginx.
$path is the path in the ZIP package.

However, this makes it impossible to create an empty directory. On the one hand, the zip format does not initially define an empty directory, and later standards and software are implemented by adding a/end 0 size file. At this point, you need to do a internal in the Nginx 0 size file, such as located in/_0. Then output
Copy the Code code as follows:
printf ("%s%d%s%s\n", ' 00000000 ', 0, '/_0 ', $path. ' /');
If you want to support the Chinese path, you can use the X-archive-charset:utf8 such as the response header, the content of your output encoding. The Nginx Zip module is converted to the standard format of UTF8 by standard. However, each software standard support for this zip is different, such as the Windows Zip directory is not supported, can only be GBK encoded directly output. Other software has different effects on encoding support. Tested winrar,7zip,windows Zip directory, winrar can be very good support. 7zip may turn part of the Chinese empty directory into a 0 size file. So, it needs to be dealt with at its own discretion.

http://www.bkjia.com/PHPjc/781816.html www.bkjia.com true http://www.bkjia.com/PHPjc/781816.html techarticle PHP itself has a zip module that can produce zip files. However, this zip module can only be packaged using local files. If you need to package the output of the file from the network, you must first save the temporary text ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.