-1

I want to show files (pdf, docx etc) in browser once click on a button instead of download.

Aleem Zada
  • 23
  • 1
  • 6
  • 2
    Welcome to stackoverflow! Could you please update your post to include the code that you're using right now and the solutions you've tried that didn't work? – Travis Britz Feb 27 '19 at 05:22
  • Travis Britz i tried multiple solutions for it using google but find nothing, so i asked here – Aleem Zada Feb 27 '19 at 05:27
  • 1
    @AleemZada if you have tried something, you should describe that, you'll save your time and ours. Please read [how to ask a good question](https://stackoverflow.com/questions/how-to-ask). – Don't Panic Feb 27 '19 at 06:15

3 Answers3

3

file() method is used to display an image or PDF directly in user's browser.

return response()->file($pathToFile);

or

return response()->file($pathToFile, $headers);

Read this more here

Afraz Ahmad
  • 5,193
  • 28
  • 38
1

i used the google docs to view pdf files.

here is my code --

<a href="http://docs.google.com/gview?url={{ URL::to($tableof1->content) }}" target="_blank">{{$tableof1->content_title}}</a>
Berns
  • 46
  • 1
  • 5
0

As far as I understood the question, you can try to display file type like images and pdf using return response()->file($pathToFile, $headers);

but you can not show docx file directly in the browser. You need some kind of conversion which browser can support in order to show docx onto the browser

Joy
  • 301
  • 1
  • 5
  • 15