Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.