PHP uses the pclzip class to implement file compression. Attached is the pclzip class download address.

WBOY
Release: 2016-07-29 08:51:39
Original
1139 people have browsed it

The example in this article describes how PHP uses the pclzip class to achieve file compression. Share it with everyone for your reference, the details are as follows:

Use PclZIp (zip format) compression, you first need to download its package file (You can click hereDownload from this site). The function of PclZip is quite powerful. It can compress and decompress, as well as some methods of adding and deleting classes, etc. Of course, we can all find these contents online, so there is no need to remember them all. We just need to be able to quickly find how to use it online when we need to use it. First of all, what we need is to import the downloaded library file, such as

<?php include('pclzip/pclzip.lib.php'); ?>
//括号里面的地址改成自己的pclzip.lib.php 文件所在地址,
//它的所有的功能都在pclzip.lib.php里面

Copy after login

. After importing it, we can use it. Here is a simple method I wrote when using it.

<?php
$zipname = "test.zip"; //压缩包的名称
$zipnames = '/zipfiles/'.$zipname; //压缩包所在路径
$z = new PclZip($zipnames); //实例化这个PclZip类
$v_list = $z->create('file.txt,data/text.txt,folder'); //将文件进行压缩
if ($v_list == 0)
{
die("Error : ".$archive->errorInfo(true)); //如果有误,提示错误信息。
}
?>

Copy after login

This is a simple zip compression. In this method, we mainly use the PclZip class in PclZip and the method create in it to create a compressed package. From the above example, we can see the following content

<?php PclZip($zip_filename); ?>
//里面是该压缩包的名称以及所在路径。并不是把名称写上就可以了。
//如果路径不对是无法找到的。
<?php PclZip::create($filelist, [optional arguments]); ?>
//create方法来创建压缩包。
//$filelist可以用数组包含文件的名称和文件夹名称或者是一个字符串来包含.
//如果是多个文件的话可以用逗号来隔开,如上面的例子。

Copy after login

Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP Operation Zip File and Compression Techniques", "Summary of PHP File Operation", "Summary of usage of php regular expressions", "Summary of usage of PHP operations and operators", "Introduction to PHP basic syntax tutorial", "Introduction to php object-oriented programming tutorial", "Summary of usage of php string (string)", "php +MySQL database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone in PHP programming.

The above introduces how PHP uses the pclzip class to achieve file compression. The pclzip class download address is attached, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!