Laravel 5 create and download zip/archive file using chumper/zipper composer package.

How to create zip file using Laravel `chumper/zipper` package. Let’s see how to create zip file or folder step by step. Let’s, first of all, install “chumper/zipper” package. So, Open command prompt and goto the root directory of the Laravel and fire below command.

composer require chumper/zipper

After installing the package open the app config file from “config/app.php” file then append below Provides and Aliases to app.php file.

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

You can now access Zipper with the Zipper alias for creating the zip file. So let’s create the zip file of images existing on the public folder. Make sure you have the “images” folder inside of the public directory and Also make sure the “thecodingstuff” directory exists inside of the public directory. If not exists please create both directories.

Then used below code for creating the zip file of images.

public function downloadZip()
{
    $images = glob(public_path('images/*'));
    \Zipper::make('thecodingstuff/filename.zip')->add($files)->close();
    return response()->download(public_path('thecodingstuff/filename.zip'));
}

If you face any issue after using above code written the comment below.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s