如何直接从浏览器从存储访问pdf文件? [英] How to access pdf file from storage directly from browser?

查看:93
本文介绍了如何直接从浏览器从存储访问pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从浏览器访问pdf文件,该文件位于laravel存储文件夹中.我不想公开存储.

I want to access a pdf file from the browser, the file is located in laravel storage folder. I don't want the storage to be public.

我不想下载(我设法下载了).我只是想获得一条路线,并在浏览器中显示该文件,例如:www.test.com/admin/showPDF/123/123_321.pdf.

I don't want to download it(that I managed to do it). I simply want to have a get route, and to show that file in the browser like: www.test.com/admin/showPDF/123/123_321.pdf.

123是一个ID.

如果我使用:

storage_path('app/'.$type.'/'.$fileName);
or
Storage::url('app/'.$type.'/'.$fileName);

返回完整的服务器路径.

return the full server path.

谢谢.

推荐答案

添加新路径以获取pdf

Add new route to get pdf

Route::get('/admin/showPDF/{$type}/{$fileName}','PDFController@pdf');

并在您的控制器中

public function pdf($type,$fileName)
    {
        $path = storage_path('app/'.$type.'/'.$fileName);
        return response()->file($path);
    }

这篇关于如何直接从浏览器从存储访问pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆