A brief analysis of PHP creating zip archive Tips _php Tutorial

Source: Internet
Author: User

When developing a Web application, it is very likely that you will encounter different formats of file--csv data, password files, XML encoded content, and different forms of binary data. Your PHP scripts will need to interact with these files frequently, reading data from them, and writing data to them. Since there are so many file formats to work with, you should not accidentally have several types of built-in functions and external libraries in PHP to connect and use almost any file format that you can name.

This PHP Create zip archive Guide is about such a file format, which may be encountered by application developers almost every day: Zip format. In general, this format is used to transfer files through e-mail and remote connections, to compress multiple files into an archive file, thus reducing the file's hard disk to occupy space and making it easier to move them. PHP can read and create these zip files through its zziplib plugin and pear's Archive_zip class.

I will assume that you already have a functioning Apache, that you have PHP installed, and that the Pear Archive_zip class is installed correctly.

Note: You can install the Pear Archive_zip package directly from the Web, or you can download it and take advantage of the instructions provided.

PHP Create zip archive file

Let's start with a simple example: dynamically create a ZIP file that includes several other files. Start with the script in List A.

List A

 
 
  1. < ? PHP
  2. Include (' archive/zip.php ');
  3. Imports
  4. $ obj = New archive_zip (' Test.zip ');
  5. Name of the zip file
  6. $ Files = Array (' Mystuff/ad.gif ',
  7. ' Mystuff/alcon.doc ',
  8. ' Mystuff/alcon.xls ');
  9. Files to store
  10. if ($obj->Create ($files)) {
  11. Echo ' Created successfully! ';
  12. } else {
  13. Echo ' Error in file Creation ';
  14. }
  15. ?>

These are the tips for PHP to create a zip archive file.


http://www.bkjia.com/PHPjc/445910.html www.bkjia.com true http://www.bkjia.com/PHPjc/445910.html techarticle when developing a Web application, it is very likely that you will encounter different formats of file CSV data, password files, XML encoded content, and different forms of binary data. Your PHP script will need ...

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