我正在尝试在视图中显示存储在“公共”文件夹之外的图像。这些是简单的概要文件映像,其路径存储在DB中。路径看起来像
/Users/myuser/Documents/Sites/myapp/app/storage/tenants/user2/images/52d645738fb9d-128-Profile (Color) copy.jpg
Run Code Online (Sandbox Code Playgroud)
由于该图像为每个用户存储了一个DB列,因此我的第一个想法是在User模型中创建一个访问器以返回该图像。我试过了:
public function getProfileImage()
{
if(!empty($this->profile_image))
{
return readfile($this->profile_image);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
这在视图中产生了不可读的字符。我还尝试了file_get_contents()来代替读取文件。关于如何实现的任何建议?
怎么样(自己测试一下就可以了):
风景:
<img src="/images/theImage.png">
Run Code Online (Sandbox Code Playgroud)
Routes.php:
Route::get('images/{image}', function($image = null)
{
$path = storage_path().'/imageFolder/' . $image;
if (file_exists($path)) {
return Response::download($path);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8604 次 |
| 最近记录: |