claudye/laracompress

Laracompress 是一个用于在项目中压缩和解压缩文件的 Laravel 扩展包。

安装: 9

依赖者: 0

建议者: 0

安全: 0

星标: 5

关注者: 2

分支: 0

公开问题: 0

类型:package

dev-main 2022-06-06 08:22 UTC

This package is auto-updated.

Last update: 2024-09-29 06:20:28 UTC


README

Laracompress 是一个用于在项目中压缩和解压缩文件的 Laravel 扩展包。

何时使用?

当您设计一个处理压缩(zip)文件的应用程序时,您将使用 laracompress,如果您需要一个快速简便的解决方案。

安装

  • 创建您的 Laravel 项目,在项目根目录中输入以下命令安装此包:

composer require claudye/laracompress

如果没有错误,一切顺利!

  • 加载服务提供者 确保将服务提供者 Laracompress\Providers\LaracompressProvider 添加到 Laravel 的服务提供者中。在文件 ./config/app.php 中,将以下类添加到服务提供者列表中
<?php
'providers' => [

       /*
        * Laravel Framework Service Providers...
        */
       Illuminate\Auth\AuthServiceProvider::class,
       
       //others services providers
       
       Laracompress\Providers\LaracompressProvider::class,

   ],

这就是开始使用 laracompress 所需的全部内容

用法

我们提供了一个门面来管理项目中路径的压缩和解压缩。

压缩

use Laracompress\Laracompress;
/**
* This function takes two arguments as parameters, the first is the path (folder or file to compress), 
* The second is the destination filename. Eg: (test.zip)
*/
Laracompress::zip($path, $zipfile);

解压缩

use Laracompress\Laracompress;
/**
* This function takes two arguments as parameters, the first is the file to decompress,
* The second argument is the name of the folder where the file will be unzipped. Eg: (/test)
*/
Laracompress::unzip($zipfile, $dir_to_extract);

辅助函数

除了使用门面,我们还提供了 zipfile() 和 unzipfile() 函数,它们与我们的门面执行相同的功能。

示例

zipfile($path, $zipfile); //zip file
unzipfile($zipfile,$dir)

感谢您使用 laracompress。