<?php namespace App\Services; use ZipArchive; class ZipArchiveService { public function makeZip() { $downloadDir= '../download'; $archiveFileName = 'archive.zip'; // create zip archive $zip = new ZipArchive; if ($zip->open($downloadDir. '/' . $archiveFileName, ZipArchive::CREATE) === TRUE) { // add file/s $file = '../path/to/file.pdf'; if(file_exists($file)) $zip->addFile($file, 'New Name.pdf'); } // download file $headers = array( 'Content-Type' => 'application/octet-stream', ); if(file_exists($downloadDir. '/' . $archiveFileName)) { return response()->download($downloadDir. '/' . $archiveFileName, $archiveFileName, $headers); } } }