This article briefly introduces the PHP operation of the ZIP compression package needs to be in the case of the need to directly display the picture or file, the method is very simple mainly using the PHP Zip File series function, Base64_encode function, I hope to have some inspiration
PHP Operation Zip Compressed package file Basic method Everyone should know how to do (if you do not understand the basic method of PHP operation zip at the bottom of this article), then how to read the files in the compressed package without the pressure, such as directly in the page to display the picture in the compressed package?
Let's show you how to display the picture file in the compressed package without pressure.
$zip _path = ' 12.zip ';//Compression packet actual path $zip = Zip_open ($zip _path);//Use Zip_open function to open the compressed package while ($re = Zip_read ($zip)) {//Read the file in the package sequentially if (!zip_entry_filesize ($re)) break;//If the file size is 0 exit operation $entry _zp = Zip_entry_open ($zip, $re, ' RB ');//Read the file in the package $ext = PathInfo ( Zip_entry_name ($re), pathinfo_extension);//Get picture file extension $buf = Zip_entry_read ($re, Zip_entry_filesize ($re));// Read file binary data echo sprintf (' ", $ext, Base64_encode ($BUF));//Use base64_ The Encode function transforms the read binary data into the input output to the page zip_entry_close ($re);//Closes the file}zip_close ($zip) in the open compressed package;//Closes the compressed package file
The most important part of this code is to use Base64_encode to convert the binary data of a picture file into a browser-readable Base64 image data.
Note: When using PHP's ZIP file series functions, make sure that the Php_zip.dll extension library is already open in your php.ini file and that there are php_zip.dll in the Ext folder in the PHP installation directory (I'm using a Windows system). If Php_zip.dll does not exist, you can get to the following PHP official PECL Extension Pack station
PHP official PECL Extension Packet Station address: Http://pecl.php.net/package/zip
Select the appropriate compression package for your PHP version;
Under Windows, you can simply drag and drop the Php_zip.dll file in the package into the Ext folder in the PHP installation directory.
Linux system needs to compile and then modify the PHP configuration file
Attach the basic function of PHP operation zip file
function |
Description |
PHP |
Zip_close () |
Close the ZIP file. |
4 |
Zip_entry_close () |
Closes an item in the ZIP file. |
4 |
Zip_entry_compressedsize () |
Returns the compressed size of an item in a ZIP file. |
4 |
Zip_entry_compressionmethod () |
Returns the compression method for an item in a ZIP file. |
4 |
Zip_entry_filesize () |
Returns the actual file size of an item in a ZIP file. |
4 |
Zip_entry_name () |
Returns the name of an item in a ZIP file. |
4 |
Zip_entry_open () |
Open an item in the ZIP file for reading. |
4 |
Zip_entry_read () |
Reads an open item in a ZIP file. |
4 |
Zip_open () |
Open the ZIP file. |
4 |
Zip_read () |
Reads the next item in the ZIP file. |
4 |
Articles you may be interested in:
PHP implementation of the check-in function of the method Example analysis de detailed
Solve the problem of memory exhaustion due to excessive php-fpm process in Linux
PHP implementation of the check-in function of the method Example analysis