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.