How to display the in-package picture with PHP without compressing the package

Source: Internet
Author: User
I believe that the basic method of using PHP to operate the ZIP archive package file, we all know how to do, then in some special circumstances we need to not be able to see the compression package of files, this need how to operate it? Today we will bring you a way to take a look at it together.

$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

Zip_close ()    closes 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 of an item in the zip file.    4    zip_entry_filesize ()    returns the actual file size of an item in the zip file.    4    zip_entry_name ()    returns the name of an item in the zip file.    4    Zip_entry_open ()    opens 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


Believe that you have seen these cases you have mastered the method, more wonderful please pay attention to the PHP Chinese network other related articles!

Related reading:

A detailed example of binary lookup and binary lookups in Java algorithms

JavaScript binary find detailed _javascript tips

JavaScript binary find the position of the character in the array (with sequence list) _javascript tips

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.