DEV Community

Seatgo
Seatgo

Posted on

Laravel: Compressing/Decompressing Files with Zipper

This is a simple wrapper for the ZipArchive method with some convenient features.

Install dependencies using Composer

composer require chumper/zipper
Enter fullscreen mode Exit fullscreen mode

Post-installation configuration

Register the service provider in the providers array in config/app.php:

Chumper\Zipper\ZipperServiceProvider::class
Enter fullscreen mode Exit fullscreen mode

Also, register the facade in the aliases array in config/app.php:

'Zipper' => Chumper\Zipper\Zipper::class
Enter fullscreen mode Exit fullscreen mode

Compressing files

use Zipper;
$arr = glob(public_path($public_path)); //$public_path is the filename to be compressed
Zipper::make(public_path($reduce_path))->add($arr)->close();  //public_path($reduce_path) is the filename after compression
Enter fullscreen mode Exit fullscreen mode

Note:

$public_path = 'aaa.txt';
$reduce_path = 'ddd.zip';
Extracting files
Extracting files
Enter fullscreen mode Exit fullscreen mode
use Zipper;
Zipper::make(path_to_compressed_file)->extractTo(path_for_extracted_files);
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
mreduar profile image
Eduar Bastidas

Why use a package that has been archived for 6 years?