PHP Packaging Compressed file Ziparchive method usage Analysis _php Skill

Source: Internet
Author: User

The example of this article describes the Ziparchive method usage of the PHP package compression file. Share to everyone for your reference, specific as follows:

In front of the pclzip of the PHP package compressed file method, today, a more simple way to use ziparchive to compress files. This is the extension of PHP, since the php5.2 version has supported this extension, if you are in use when there are errors, look at the php.ini inside the EXTENSION=PHP_ Zip.dll before the semicolon is removed, and then restart Apache so you can use this class library.

Using ziparchive compressed file is very simple, PHP website has provided me with a lot of related examples, you can see the http://www.php.net/manual/zh/class.ziparchive.php, for example:

<?php
$zip = new ziparchive;//First Instantiate this class
if ($zip->open (' test.zip ') = = TRUE) {//Then see if there is a test.zip this compressed package
  $zip->addfile (' too.php ');
  $zip->addfile (' test.php '); Add too.php and test.php two files to the Test.zip compression pack
  $zip->close ();//Close
  echo ' OK ';
} else {
  echo ' failed ';
}
?>

Here are some parameter descriptions:

<?php
/******** ziparchive Optional Parameters *******//
*
1.ziparchive::addemptydir
Add a new file directory
2. Ziparchive::addfile 
adds the file to the specified zip compression package.
3.ziparchive::addfromstring 
added files add content to the
4.ziparchive::close 
close ziparchive
5. Ziparchive::extractto Unzip 
The compressed package
6.ziparchive::open
open a zip compression package
7.ziparchive::getstatusstring
returns the state content at the time of compression, including error messages, compression information, and so on
8.ZipArchive::d eleteindex
Delete a file in a compressed package, such as: Deleteindex (0) Delete the first file
9.ZipArchive::d eletename
Deletes a file name from a compressed package and deletes the file as well.
......
* *
?>

In short, as long as your php5.2 version above, the use of ziparchive for file compression is more convenient. Specific and Pclzip which one to run faster, this LEI has not been tested, we are interested in tossing and tossing.

More about PHP Interested readers can view the site topics: "PHP operation zip file and compression skills summary", "PHP file Operation Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP basic Grammar Introductory Course", " Introduction to PHP object-oriented programming, "PHP string (String) Usage Summary", "Php+mysql Database Operations Introduction Tutorial" and "PHP Common database Operation tips Summary"

I hope this article will help you with the PHP program design.

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.