Laravel 5 Multiple Download File

Laravel 5 Multiple Download File

It is not possible to send more than one file simultaneously over the same request with the HTTP protocol. Laravel also does not support this. You have to pack the files in, for example, a zip file.

Also see

  • download multiple files as zip in php
  • Zipper (a handy wrapper for ZipArchive)

I want to download multiple files from my storage folder in Laravel

Looks like you didn't add any files to your Zip.

I think:

$zipper->make($filepath.'doc.zip');

Should be:

$zipper->make($filepath.'doc.zip')->add($fi)->close();

Make sure the files and zip are in the storage folder.

Creating zip of multiple files and download in laravel

Only pure php code.

public function makeZipWithFiles(string $zipPathAndName, array $filesAndPaths): void {
$zip = new ZipArchive();
$tempFile = tmpfile();
$tempFileUri = stream_get_meta_data($tempFile)['uri'];

if ($zip->open($tempFileUri, ZipArchive::CREATE) !== TRUE) {
echo 'Could not open ZIP file.';
return;
}

// Add File in ZipArchive
foreach($filesAndPaths as $file)
{
if (! $zip->addFile($file, basename($file))) {
echo 'Could not add file to ZIP: ' . $file;
}
}
// Close ZipArchive
$zip->close();

echo 'Path:' . $zipPathAndName;
rename($tempFileUri, $zipPathAndName);
}

Laravel 5.3 multiple file uploads

It works now like this:

$files = $request->file('attachment');

if($request->hasFile('attachment'))
{
foreach ($files as $file) {
$file->store('users/' . $this->user->id . '/messages');
}
}

I had to append [] after the value of the name attribute, so:

<input type="file" name="attachment[]" multiple>

Download button in Laravel with multiple documents ID's on button

You need to pass the $fileId within an array for more than one id

$file = Documents::findOrFail([$fileId]);
$number_of_files = count($file);
if ($number_of_files > 1) {
// Push all the files in a zip and send the zip as download
} else {
// Send the file as a download
$file = public_path(). "/uploads/" . $file->document_path;
return Response::download($file, 'filename.pdf');
}


Related Topics



Leave a reply



Submit