-
-
Save neylsongularte/ae26d594876131f0f7d9edc0fda222b9 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