如何在 Laravel 11 中的私有磁盘存储中在 iframe 中显示 pdf?

问题描述 投票:0回答:1

如何在 Laravel 11 中的私有磁盘存储中在 iframe 中显示 pdf?

'private' => [
            'driver' => 'local',
            'root' => storage_path('app/private'),
            'visibility' => 'private',
        ],

试过

$path = Storage::disk('private')->path($filename);

php laravel filesystems
1个回答
0
投票

我之前使用过这个解决方法,它对我来说效果很好,它是关于创建一个用于查看 pdf 的新路径,然后在你的 iframe 中将其用作 src

这是新的路由控制器功能的代码

file = Storage::disk('private')->get($file_path);
    
return response($file, 200)->header('Content-Type', 'application/pdf');

例如,您可以创建一条新路线

⁠"/view-pdf/{file_path}"

并在该路由的功能中使用我上面提到的代码,然后在 iframe 的 src 属性中使用该路由

© www.soinside.com 2019 - 2024. All rights reserved.