Home >Backend Development >PHP Tutorial >Laravel如何对文件压缩解压

Laravel如何对文件压缩解压

PHPz
PHPzOriginal
2016-06-06 20:33:473313browse

Laravel对文件压缩解压的方法:首先使用composer引入“chumper/zipper”;然后配置“app/config/app.php”文件;最后使用“Zipper”压缩或解压文件即可。

Laravel如何对文件压缩解压

Laravel如何对文件压缩解压?

使用前提:laravel 版本必须大于 5

1、使用 composer 引入

composer require chumper/zipper

2、配置 app/config/app.php

Chumper\Zipper\ZipperServiceProvider::class
 'Zipper' => Chumper\Zipper\Zipper::class

3、压缩文件

***** 必须使用 use 引文文件

    use Chumper\Zipper\Zipper;
    $zipper=new Zipper();
    $arr = glob(public_path($public_path));   //$public_path  被压缩的文件名
    $zipper->make(public_path($reduce_path))->add($arr)->close();  //public_path($reduce_path)  压缩之后的文件名

    注:

    $public_path = 'aaa.txt';
    $reduce_path = 'ddd.zip';

4、解压文件

***** 必须使用 use 引文文件

    use Chumper\Zipper\Zipper;
    $zip = new Zipper();
    $zip->make(压缩的文件目录)->extractTo(压缩之后的目录);

更多相关知识,请访问PHP中文网

Statement:
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