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.

Read Also:  Vuejs Timing Events setTimeout Example

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', '[email protected]');

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

<?php
   
namespace App\Http\Controllers;
   
use Illuminate\Http\Request;
use File;
use ZipArchive;
  
class ProductInvoiceController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function createDownloadZipFiles()
    {
        $zip = new ZipArchive;
   
        $fileName = 'w3movi.zip';
   
        if ($zip->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.

Read Also:  PHP Remove specific value from array

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 Also:  Paypal Recurring Payments PHP REST API Example

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Remove Item from Array using AngularJS
  2. Read Also:  Create Order and Invoice using Magento
  3. Read Also:  Vuejs Clone Array Example with Demo
  4. Read Also:  PayPal Payment Gateway PHP Source Code
  5. Read Also:  PHP Simple Image Upload and Display Source Code
  6. Read Also:  Top 10 Advanced PHP Interview Questions Answers
  7. Read Also:  Laravel 5.6 Dependent Dynamic dropdown Example Tutorial
  8. Read Also:  Paypal Recurring Payments PHP REST API Example
  9. Read Also:  Vuejs Timing Events setTimeout Example
  10. Read Also:  PHP Simple Image Upload and Display Source Code
CLOSEX