PHP uses Pclzip class to implement file compression method (with Pclzip class download address) _php Tips

Source: Internet
Author: User
Tags php regular expression

This example describes the way PHP uses the Pclzip class to implement file compression. Share to everyone for your reference, specific as follows:

Use Pclzip (zip format) compression, first need to download its package file ( Click here to download ). The Pclzip function is still quite powerful, it can compress and decompress, and some methods of adding and removing classes and so on. Of course, we can find these content online, not necessarily have to remember. We just need to use the time we can quickly find a way to use the Internet. The first thing we need is to introduce the downloaded library file, such as

<?php include (' pclzip/pclzip.lib.php '),?>
//brackets inside the address changed to its own pclzip.lib.php file address,
// All of its functions are in pclzip.lib.php.

After the introduction we can use it, the following is a simple way to write when I use.

<?php
$zipname = "test.zip";//Compressed package name
$zipnames = '/zipfiles/'. $zipname;//Zip package path
$z = new Pclzip ($ Zipnames); Instantiate this pclzip class
$v _list = $z->create (' File.txt,data/text.txt,folder ');//compress the file
if ($v _list = 0)
{
die ("Error:". $archive->errorinfo (true)); If incorrect, prompts for an error message.
}
? >

This is a simple zip compression is done, in this method we mainly use the Pclzip inside the Pclzip class and its inside create a compression package. From the above example, we can see the following:

<?php Pclzip ($zip _filename);?>
//Inside is the name of the compressed package and the path in which it resides. Not to write the name on it.
//If the path is incorrect, it cannot be found.
<?php pclzip::create ($filelist, [optional arguments]);?>
//create method to create a compressed package.
//$filelist You can include the name and folder name of the file or a string to include in the array.
If multiple files can be separated by commas, as in the example above.

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.