Try to access 'storage/app/folder1/a.png' from my view
public function viewStorageFiles()
{
$fileFullPath = Storage::disk('local')->path('folder1/a.png');
$fileUrl = Storage::disk('local')->url('app/folder1/a.png');
$storage_path = storage_path('app/folder1/a.png');
return view('email.fileDownload')->with([
'fileFullPath' => $fileFullPath,
'fileUrl' => $fileUrl,
'storage_path' => $storage_path,
]);
}
In view : email.fileDownload
<div>
<p> asset($fileUrl) ==> {{asset($fileUrl)}}</p>
<img src="{{asset($fileUrl)}}"/>
</div>
<div>
<p> url($fileUrl) ==> {{url($fileUrl)}}</p>
<img src="{{url($fileUrl)}}"/>
</div>
<div>
<p> storage_path($fileUrl) ==> {{storage_path($fileUrl)}}</p>
<img src="{{storage_path($fileUrl)}}"/>
</div>
最佳答案
这个问题可能有很多答案!
您可以使用以下命令创建从“public/storage”到“storage/app/public”的符号链接(symbolic link)
:
php artisan storage:link
以上命令会将您的 storage/app/public
目录映射到 public
目录。
现在假设您的 storage/app/public
目录中有 user1.jpg
和 user2.jpg
文件,您可以访问它们通过以下方式:
http://your-domain.com/storage/user1.jpg
http://your-domain.com/storage/user2.jpg
* 根据您的评论更新了我的答案:*
您可以从受某些中间件保护的路由返回文件响应!
例如 - 以下路由从不可公开访问的 storage/app/uploads
目录返回文件响应:
Route::get('storage/{file}', function ($file) {
$path = storage_path('app' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $file);
return response()->file($path);
});
您可以无论如何保护上述路线并在您的 View 中使用它..
我希望有所帮助..
关于php - 获取/读取 laravel 5.8 存储非公共(public)文件夹文件以查看?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55479687/