【发布时间】:2014-02-03 16:52:19
【问题描述】:
我正在尝试在我的视图中显示存储在“公共”文件夹之外的图像。这些是简单的配置文件图像,其路径存储在数据库中。路径看起来像
/Users/myuser/Documents/Sites/myapp/app/storage/tenants/user2/images/52d645738fb9d-128-Profile (Color) copy.jpg
由于图像为每个用户存储了一个 DB 列,我的第一个想法是在 User 模型中创建一个访问器来返回图像。我试过了:
public function getProfileImage()
{
if(!empty($this->profile_image))
{
return readfile($this->profile_image);
}
return null;
}
这会在视图中产生不可读的字符。我还尝试使用 file_get_contents() 代替读取文件。关于如何实现这一点有什么建议吗?
【问题讨论】:
-
this stackoverflow.com/questions/5630266/a-php-file-as-img-src 似乎很好地涵盖了这一点。
-
谢谢。这有帮助。我读过它——但直到我重读它才明白。在下面发布了答案。