Create a ZIP file using PHPPclZip

Source: Internet
Author: User
Tags create zip decompress zip
PHP compression and decompression class PclZip can be used to compress and decompress Zip files (WinZip and PKZIP). It can process ZIP files, this includes generating compressed files, listing compressed files, and extracting ZIP files. The latest version is the PclZip2.8.2PclZip class. How to create a ZIP file is defined: PclZip: create ($ filelist,

PHP compression and decompression class PclZip can be used to compress and decompress Zip files (WinZip and PKZIP). It can process ZIP files, this includes generating compressed files, listing compressed files, and extracting ZIP files. The latest version is PclZip 2.8.2. How to create a ZIP file using the PclZip: create ($ filelist,

PHP compression and decompression class PclZipIt can compress and decompress Zip files (WinZip and PKZIP). It can process ZIP files, including generating compressed files, listing compressed files, and decompressing ZIP files.

The latest version is PclZip 2.8.2.

Define the method for creating a ZIP file in the PclZip class

Method:

PclZip: create ($ filelist, [optional arguments])

This method is used to generate a ZIP compressed file for the specified file or all files in the specified folder.

Parameter description:

$ Filelist can be:

  • An array of one or more file names or folders, such as array('file.txt ', 'Data/text.txt', 'folder ')
  • A single file name or a folder string, such as: file.txt
  • Strings of multiple file names or folders separated by commas (,), such as file.txt, data/text.txt, and folder.

Arguments is an optional parameter, but I must also explain several important parameters. It is often used as follows:

  • PCLZIP_OPT_REMOVE_ALL_PATH, which can delete all directories in the compressed file;
  • PCLZIP_OPT_REMOVE_PATH, which can delete a specified directory in the compressed file;
  • PCLZIP_OPT_ADD_PATH, which can uniformly add compressed files to a directory;
Use the PclZip class to create ZIP files

Use the PclZip class to generate ZIP files on the server, such:

Method call (require before use ):

Require_once ('pclzip. lib. php ');

Set the path to save the generated ZIP file:

$ File_zipname = file_directory_path (). '/zip/'. crc32 (md5 ($ id). '-'. $ version. ". zip ";
$ Archive = new PclZip ($ file_zipname );

Delete all directories in the compressed file:

$list = $archive->create("data/file.txt images/image.gif", PCLZIP_OPT_REMOVE_ALL_PATH);

Delete a specified directory in the compressed file:

$list = $archive->add("/usr/local/user/test/file.txt", PCLZIP_OPT_REMOVE_PATH, "/usr/local/user");

Add the compressed file to a directory:

$list = $archive->create("file.txt,image.gif", PCLZIP_OPT_ADD_PATH, "backup"); 

(...)
Read the rest of PHP PclZip to create a ZIP file (36 words)

©Lixiphp for LixiPHP, 2013. | Permalink | No comment | Add to del. icio. us
Post tags: PclZip, PHP, ZIP, compressed and decompressed

Feed enhanced by Better Feed from Ozh

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.