You probably know the Response::inline() method from Laravel 4.
Really useful for to show inline images and files, but this method is not longer available in Laravel 5 .
I’ve created the following function to get inline image on Laravel 5.
Add the following namespaces to your class:
1 2 |
use File; use Illuminate\Http\Response; |
Add the following function to your controller or internal class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
/** * Display file directly on browser * @author Victor Cruz * * @param string $path File path */ function inline($path) { if (!File::exists($path)) throw new Exception("File does not exist"); $filetype = File::mimeType($path); $response = Response( File::get($path), 200 ); $response->header('Content-Type', $filetype); return $response; } |
Finally call the function from your controller:
1 2 3 4 5 6 7 8 |
/** * Controller method * */ public function index() { return $this->inline("/path/to/file.jpg"); } |