Recommend a PHP compression and decompression class pclzip_php tutorial

Source: Internet
Author: User
Tags php class
Pclzip is a very powerful PHP class for compressing and extracting zip files, and the Pclzip library is capable of compressing and decompressing compressed archives (WINZIP, PKZIP) in zip format, and can process such files, including generating compressed file, List the contents of the archive, unzip the file, and so on. You can also add or delete files from existing zip packages.

Official website: http://www.phpconcept.net/pclzip/

Recently in the development of my WordPress plugin Sharelink, in this process, found Pclzip This operation zip file PHP class, have to recommend the next. Simple, easy to use, strong is my evaluation of it.

Another recommended reason is that in its source code I found a php function parameters of the lewd usage. An example is shown below.

Generate ZIP file

Usage One:

 
  Create (' File.txt,data/text.txt,folder '), if ($v _list = = 0) {die ("Error:". $archive->errorinfo (True));}? >

Usage Two:

 
  Create (' Data/file.txt,data/text.txt ', Pclzip_opt_remove_path, ' data ',                            pclzip_opt_add_path, ' Install '); if ($v _ List = = 0) {die ("Error:". $archive->errorinfo (True));}? >

If you see the parameters of the Create method, and then look at the method prototypes, you know how to be lewd. At least I haven't used that yet.

The following is a simple compression of the entire station for the backup code:

 
  Create ($_server[' Document_root '), pclzip_opt_remove_path,$_server[' Document_root ']); if ($v _list = = 0) {echo ' exception: '. $z->errorinfo (TRUE);} else {echo ' backup succeeded ';}? >

Other ways to use:

 Extract (Pclzip_opt_path, "extract/folder/"); Add this directory in the compressed file, after the completion of the archive will have the backup directory, backup will have these two files $list = $archive->create ("File.txt,image.gif", Pclzip_opt_               Add_path, "Backup"); Remove part of the path, and this will become test/file.txt $list = $archive->add ("/usr/local/user/test/file.txt", Pclzip_opt_remove_path, "               /usr/local/user "); All the paths are removed, after the compression file is established, there will only be file.txt and image.gif, there will be no directory $list = $archive->create ("Data/file.txt images/image.gif",               Pclzip_opt_remove_all_path);           The CHMOD of the extracted files is set to 0777 $list = $archive->extract (pclzip_opt_set_chmod, 0777);       Unzip part of the file, this parameter is used to determine the name of the file//argument can be used in the following array $rule _list[0] = ' test/aaa.txt ';       $rule _list[1] = ' test/ddd.txt ';       Or the following, in a string, separate each file to be decompressed with a comma $rule _list = "Test/aaa.txt,test/ddd.txt";               $list = $archive->extract (pclzip_opt_by_name, $rule _list); Unzip part of the file, using PHP ereg () function, the file name is successful will be uncompressed $list = $archive->extract (pclzip_opT_by_ereg, "AA");       Unzip part of the file, using PHP preg_match () function, the file name of the success will be uncompressed $list = $archive->extract (pclzip_opt_by_preg, "/^bb/"); If the above two functions do not understand, please first study the formal notation (Regular Expression)//According to the index of the elements in the array decompression, but I do not quite understand index what = =a $list = $archive->e               Xtract (Pclzip_opt_by_index, Array (' 0-1 ', ' 6-7 ')); Unzip an archive content into a string $list = $archive->extract (pclzip_opt_by_name, "Data/readme.txt", pclzip_opt_extract_as_string)               ; After extracting an archive content, the direct output (echo) $list = $archive->extract (pclzip_opt_by_name, "Data/readme.txt", Pclzip_opt_extract_in_               OUTPUT);               Adds a file to a compressed file, but does not compress the file $list = $archive->add ("Data/file.txt", pclzip_opt_no_compression);               Add an annotation to this compression file, and if it is already annotated, it will be overwritten $list = $archive->create ("Data", Pclzip_opt_comment, "Add a COMMENT"); Add an annotation to this compression file, and if there is an annotation, it will be followed $list = $archive->add ("Data", Pclzip_opt_add_comment, "add a COMMENT after the E           Xisting one ");    Add an annotation to this compression file, and if there is an annotation, it will be preceded by the original note $list = $archive->add ("Data", Pclzip_opt_prepend_comment, "Add a COMMENT B      Efore the existing one "); ?>

Class Library Download: Pclzip-2-8-2.zip

http://www.bkjia.com/PHPjc/752511.html www.bkjia.com true http://www.bkjia.com/PHPjc/752511.html techarticle Pclzip is a very powerful PHP class for compressing and extracting zip files, the Pclzip library is able to compress and decompress compressed archives (WINZIP, PKZIP) in zip format, and can process such files ...

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