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