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!
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
Post a Comment