Creating zip of multiple files and download in Laravel.

2019-09-17 17:13:17 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