如何在 Laravel 11 中的私有磁盘存储中在 iframe 中显示 pdf?
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'visibility' => 'private',
],
试过
$path = Storage::disk('private')->path($filename);
我之前使用过这个解决方法,它对我来说效果很好,它是关于创建一个用于查看 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 属性中使用该路由