0

I need to display a pdf in my website, but I need to keep it out of the public folder and do some validations before showing it.

I was researching a little and now I know that I have to keep it in a folder like storage. But I don´t know how to retrieve it and render it in the browser. I know that in recent laravel versions you can use response()->file() to achieve this, inside a controller.

But in the documentation there is no reference to that type of response in older versions of laravel. I need to do it in laravel 5.0.

Edit: i need a solution for older laravel versions as i said, specifically for laravel 5.0. I can´t use newer solutions.

Sampudon
  • 85
  • 1
  • 8
  • Possible duplicate of [Laravel 5 - How to access image uploaded in storage within View?](https://stackoverflow.com/questions/30191330/laravel-5-how-to-access-image-uploaded-in-storage-within-view) – Andrew May 28 '18 at 19:29

2 Answers2

1

use plain php, you just need add headers and print file

header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=filename.pdf");

return response(file_get_contents(storage_path('path to file in storage')));
Dry7
  • 861
  • 1
  • 8
  • 17
  • This gives me almost what i need. But it throws an error when tries to load the pdf. At least i get the response and the browser loads the pdf viewer. – Sampudon May 28 '18 at 19:56
1

This may be what you need:

$contents = Storage::get('file.jpg');

https://laravel.com/docs/5.0/filesystem#basic-usage

Andrew
  • 18,680
  • 13
  • 103
  • 118
  • Will this display the pdf with the browser "plugin", with zoom controls and everything? Thank you. – Sampudon May 28 '18 at 19:46
  • No, see the other answer for that or maybe this question https://stackoverflow.com/questions/18040386/how-to-display-pdf-in-php – Andrew May 28 '18 at 19:49