Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// imagine $imageIds is a get parameter with a comma seperated string of ID's
// Eample: http://localhost/download-zip?images=1,2,3,4
Route::get("/download-zip", function ($images) {
$imageIds = explode(",", $images);
// This is an eloquent model
$images = Images::find($imageIds);
if (!$images) {
return Response::make("No images found", 404);
$zipFileName = tempnam("tmp", "zip");
// Open zip file
$zip = (new ZipArchive())->open($zipFileName;, ZipArchive::OVERWRITE);
// Add each file
foreach ($images as $image) {
$zip->addFromString(image->filename, base64_decode($$image->base64_string));
// Close the file
// Return the file response
return response()->file($zipFileName);
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.