Last active
December 3, 2021 19:53
-
-
Save juarezfranco/15dac0af0f5ab95b6ba42e0f05adbd49 to your computer and use it in GitHub Desktop.
laravel - baixar arquivos grandes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Laravel\Lumen\Http\ResponseFactory; // para lumen | |
use Illuminate\Http\Response; // para laravel | |
ResponseFactory::macro('baixarStream', function ($stream) { | |
return response()->stream(function () use ($stream) { | |
while (!feof($stream)) { | |
echo fread($stream, 1024); | |
} | |
fclose($stream); | |
}); | |
}); | |
// exemplo de uso | |
return response()->baixarStream(Storage::readStream('arquivo.pdf')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@neylsongularte