Skip to content

Instantly share code, notes, and snippets.

@grandmanitou
Created January 20, 2020 13:56
Show Gist options
  • Save grandmanitou/ae636a0420392545edb0b27ebb5ba38e to your computer and use it in GitHub Desktop.
Save grandmanitou/ae636a0420392545edb0b27ebb5ba38e to your computer and use it in GitHub Desktop.
Create a zip file without keeping it on disk
$options = new \ZipStream\Option\Archive();
$options->setSendHttpHeaders(true);
$options->setDeflateLevel(9);
//$options->setEnableZip64(false);
$zip = new \ZipStream\ZipStream('fichiers.zip', $options);
foreach($clients as $client) {
$documentName = $client->getFirstMedia('document')->file_name;
$documentPath = str_replace(auth()->user()->email, $client->user_email, $client->getFirstMediaPath('document'));
$zip->addFileFromPath(Str::slug(trim($client->user_email), '-') . '/' . $documentName, $documentPath);
}
# finish the zip stream
$zip->finish();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment