php - Laravel - display a PDF file in storage without forcing download? -


i have pdf file stored in app/storage/, , want authenticated users able view file. know can make them download using

return response::download($path, $filename, $headers); 

but wondering if there way make them view file directly in browser, example when using google chrome built-in pdf viewer. appreciated!

update 2017

as of laravel 5.2 documented under other response types can use file helper display file in user's browser.

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

source/thanks below answer

outdated answer 2014

you need send contents of file browser , tell content type rather tell browser download it.

$filename = 'test.pdf'; $path = storage_path($filename);  return response::make(file_get_contents($path), 200, [     'content-type' => 'application/pdf',     'content-disposition' => 'inline; filename="'.$filename.'"' ]); 

if use response::download automatically sets content-disposition attachment causes browser download it. see this question differences between content-disposition inline , attachment.

edit: per request in comments, should point out you'd need use response @ beginning of file in order use facade.

use response; 

or qualified namespace if request isn't aliased illuminate's response facade.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -