Added the. ZIP file reading function in PHP.

Source: Internet
Author: User
Tags zip extension

This module uses the functions of the zziplib library by Guido draheim to transparently read zip compressed archives and the files inside them.
This module uses the zziplib Library (Guido draheim) to read zip compressed files and files in it.

Please note that zziplib only provides a subset of functions provided in a full implementation of the zip compression algorithm and can only read ZIP file archives. A normal zip utility is needed to create the ZIP file archives read by this library.
Note: This library is only a subset of all zip extension functions and can only read the content in the zip document. A common zip environment requires creation of zip files

Zip support in PHP is not enabled by default. You will need to use the -- with-zip configuration option when compiling PHP to enable zip support. This module requires zziplib version> = 0.10.6.
PHP does not support zip by default. You need to use the -- with-zip configuration to compile your php. This module requires the zzpilib version> = 0.10.6

Note: Zip support before PHP 4.0.7 is experimental. This section reflects the zip extension as it exists in PHP 4.0.7 and later.
Note: Zip is tested before 4.0.7. This chapter is written in php4.0.7 and later versions.

Example usage
This example opens a zip file archive, reads each file in the archive and prints out its contents. The test2.php archive used in this example is one of the test archives in the zziplib source distribution.

Example 1. Zip usage example

<? PHP

$ Zip = zip_open ("/tmp/ ");

If ($ zip ){

While ($ zip_entry = zip_read ($ zip )){
Echo "name:". zip_entry_name ($ zip_entry). "\ n ";
Echo "actual filesize:". zip_entry_filesize ($ zip_entry). "\ n ";
Echo "compressed size:". zip_entry_compressedsize ($ zip_entry). "\ n ";
Echo "compression method:". zip_entry_compressionmethod ($ zip_entry). "\ n ";

If (zip_entry_open ($ zip, $ zip_entry, "R ")){
Echo "File Contents: \ n ";
$ Buf = zip_entry_read ($ zip_entry, zip_entry_filesize ($ zip_entry ));
Echo "$ Buf \ n ";

Zip_entry_close ($ zip_entry );
Echo "\ n ";


Zip_close ($ zip );



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: 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.