Laravel 6 create zip archive file and download example

Today, We want to share with you Laravel 6 create zip archive file and download example.In this post we will show you , hear for How to create and download a Zip file with PHP Laravel 6 we will give you demo and example for implement.In this post, we will learn about Laravel 6 – How to create zip file and download using ZipArchive ?, with an example.

Laravel 6 create zip archive file and download example

There are the Following The simple About Laravel 6 create zip archive file and download example Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to Create Zip File and Download in Laravel 6?, so the some major files and Directory structures for this example is following below.

In this article i will let you know how to generate zip file and download as response in laravel 6 application using ZipArchive composer package. you have to just follow few step to generate zip file in laravel 6 web application.

Step 1: Create a Laravel 6 Route

routes/web.php

Route::get('product-invoice-zip', 'ProductInvoiceController@createDownloadZipFiles');

Step 2: Create a Laravel 6 Controller

Same things as above for laravel 6 route, step by step I will included one new simple method for route. Like as a createDownloadZipFiles() will make a new zip file as well as simple fource fully download as response, therefor let’s include bellow source code:

app/Http/Controllers/ProductInvoiceController.php

open(public_path($fileName), ZipArchive::CREATE) === TRUE)
        {
            $files = File::files(public_path('productsFiles'));
   
            foreach ($files as $key => $value) {
                $relativeNameInZipFile = basename($value);
                $zip->addFile($value, $relativeNameInZipFile);
            }
             
            $zip->close();
        }
    
        return response()->download(public_path($fileName));
    }
}

Step 3: Run Laravel 6 Project

But make sure We have simple “productsFiles” folder in main your public directory as well as included some pdf files on that file therefor it will make a latest zip file with those simple files.

php artisan serve

Now Last step, We can open simple bellow URL on your Any browser:

http://localhost:8000/product-invoice-zip
Web Programming Tutorials Example with Demo

Tags Laravel 6 ZIP File Download

laravel 6 zip download response, laravel 6 create zip file, laravel 6 create zip file and download, laravel 6 create zip from folder, create zip file and download in laravel 6, how to create zip file in laravel 6 using ziparchive, laravel download zip file, laravel 6 download zip archive file, create zip file in laravel 6 example, laravel 6 ziparchive, laravel 6 response download zip, laravel 6 unzip file, laravel 6 upload zip file

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Laravel 6 Make zip archive file and download example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment