Search code examples
phplaravelzip

Undefind Property Error while creating Zip file in Laravel using ZipArchive


I'm getting following Error while to creating Zip file in laravel using ZipArchive which will have all the PDF files

"Undefined property: ZipArchive::$close"

CONTROLLER:

public function downloadZip(Request $request)
    {            
            @$job_id = $request->job_id;
            @$filenames = DB::table('analytics_report')->where('job_id',$job_id)->get()->pluck('filename')->toArray();
            @$zipname = $request->job_id;
            $zip = new \ZipArchive;
            $zip->open($zipname, \ZipArchive::CREATE);
            foreach ($filenames as $filename){
                $zip->addFile($filename);
            }
            $zip->close;
            @$path = '../storage/app/public/bks/case_1/'.$zipname;
     }

Solution

  • $zip->close();
    

    You're missing the parantheses to make it a function call - currently you're trying to access a property $close on $zip, which doesn't exist.