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.

PHP Download Archive file from URL

How to Download Archive file from URL using PHP. It’s Very easy tricks to download archive file from server or URL. We are using download file_put_contentthe file. just used below code for the download file.

Using this code you can transfer file server to server without download. you can transfer your project from one server to another server without download file and without wasting time on download and upload the file. using this trick you can transfer around 21GB file from one server to another server.

file_put_contents("zipname.zip", fopen("http://example.com/filename.zip", 'r'));

If you face any problem after using this code please write a comment.