In this paper, a brief introduction
PHPThe operation of the ZIP compression package needs to be in the case of no pressure on how to directly display the pictures or files, the method is very simple mainly using the
PHPIn the Zip File series function, Base64_encode function, I hope you can have some inspiration and improve their
PHPTechnology.
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 zip File. |
4 |
zip_entry_close () |
Close one of the items 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 the zip file. |
4 |
zip_entry_open () |
Open an item in the ZIP file for reading. |
4 |
zip_entry_read () |
reads an open project from a zip file. |
4 |
zip_open () |
open the zip file. |
4 |
zip_read () |
reads the next item in the zip file. |
4 |