LaravelPHP

Laravel Create and Download Zip File Example using chumper/zipper

Sometimes, we need to create file of our project directory and give to download that zip file to users. we are always prefer zip file because it is very safe and secure from virus. If you want to generate zip file and download that file in your laravel 5application then you do it easily using chumper/zipper composer package. In this post I give you example to create zip file and download from scratch. So first we have to follow bellow step for install package.

First fire following command on your terminal.

Installation Package

composer require chumper/zipper

After install this package, Now open config/app.php file and add service provider and aliase.

'providers' => [
	....
	'Chumper\Zipper\ZipperServiceProvider',
],
'aliases' => [
	....
	'Zipper' => 'Chumper\Zipper\Zipper'
],

ok, now we are ready to use Zipper class globally. So now use can use how to create zip file and download it that write in your controller this way. i added controller function for doneload zip file so you can use anyway.

Make sure you have two folder in your public directory:

1.js(with some files)

2.mydir(store zip file here)

Controller Method

public function downloadZip()
{
    $files = glob(public_path('js/*'));
    Zipper::make('mydir/mytest3.zip')->add($files);

   
    return response()->download(public_path('mydir/mytest3.zip'));
}

Try this it will help you and for more information click here: Zipper.

Feel free to comment if you have any query.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button