php - How Do I return a file for download in Laravel -
i need able give user file download, , created route (unless can link specific user's cv in blade). files stored in storage/app/cv/ directory. created route such:
route::get('test', function() { $destinationpath = config('app.cvdestinationpath') . "/static_file.pdf"; $uploaded = storage::get($destinationpath); return $uploaded; } however route giving me weird output. think file converting file html or something. me return file (it pdf, doc, or docx, or plain text). file not stored in public directory!
you can use "response" download headers:
<?php use illuminate\support\facades\response; route::get('test', function() { $destinationpath = config('app.cvdestinationpath') . "/static_file.pdf"; return response()->download($destinationpath); } ?> checkout link https://laravel.com/docs/5.5/responses#file-downloads find out more e.g. response->file($destinationpath) forces browser display file (.pdf in case) user using lokal plugins.
Comments
Post a Comment