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

Laravel如何对文件压缩解压

PHPz
Release: 2020-09-04 18:06:41
Original
3336 people have browsed it

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

Laravel如何对文件压缩解压

Laravel如何对文件压缩解压?

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

1、使用 composer 引入

composer require chumper/zipper
Copy after login

2、配置 app/config/app.php

Chumper\Zipper\ZipperServiceProvider::class
 'Zipper' => Chumper\Zipper\Zipper::class
Copy after login

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)  压缩之后的文件名
Copy after login

注:

    $public_path = 'aaa.txt';
    $reduce_path = 'ddd.zip';
Copy after login

4、解压文件

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

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

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

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