php ZipArchive压缩文件

    public function zip_file($file_list, $zipped_file_name)
    {
        $zipped_file_name = $zipped_file_name.".zip";
        $zip = new ZipArchive;
        if ($zip->open($this->tmp_file_path.$zipped_file_name, ZipArchive::CREATE) === TRUE) {
            foreach ($file_list as $key => $value) {
                // 添加文件到 ZipArchive
                $zip->addFile($value['path'], $value['name']);
                //删除已经追加进zip的文件
                unlink($value['path']);
            }
            // 关闭 ZipArchive
            $zip->close();
        }
        return $this->tmp_file_path.$zipped_file_name;
    }

1.新建一个ZipArchive的对象,通过ZipArchive的对象处理zip文件

2.if中间的判断:如果对zip对象操作成功(在这里是指指定的zip文件不存在则创建一个),则会返回true

3.添加文件到指定目录下的zip,删除源文件

4.关闭zip

参考:

https://my.oschina.net/junn/blog/104464

猜你喜欢

转载自www.cnblogs.com/liyuanliu/p/9962455.html
今日推荐