Creating zip of multiple files and download in Laravel.

2024-04-27 08:00:48 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