Creating zip of multiple files and download in Laravel.

2023-11-28 17:27:20 Bikas Laravel

How to zip multiple files and download in Laravel?

Use Zipper package by Chumper to zip files in laravel.

Install Chumper/Zipper package and add below function in your controller to start creating zip files in Laravel.

public function downloadZip($id){
    $headers = ["Content-Type"=>"application/zip"];
    $fileName = $id.".zip"; // name of zip
    Zipper::make(public_path('/documents/'.$id.'.zip')) //file path for zip file
        ->add(public_path()."/documents/".$id.'/')->close(); //files to be zipped

    return response()
    ->download(public_path('/documents/'.$fileName),$fileName, $headers);

This post is submitted by one of our members. You may submit a new post here.

Related Tricks