【发布时间】:2015-09-11 10:48:32
【问题描述】:
我需要在页面加载时查看个人资料图片。我已经使用 laravel 存储上传图片,但我不知道如何检索和查看图片。请检查我的以下代码并帮助我。
当前图片文件夹是 storage/app/1/1.jpeg
Laravel 代码
public function index()
{
$id = Input::get('id');
User::findOrFail($id);
$file = Storage::get($id.'/'.$id.'.'.'jpeg');
return response($file, 200)->header('Content-Type', 'image/jpeg');
}
JS
<script>
$(function(){
$.post("/viewProfile/image", { id: 1 })
.done(function( data ) {
$('#responseImage').html('<img src="'+data+'">');
});
})
</script>
HTML
<div id="responseImage"> </div>
Firebug 控制台响应
Please find the attached file
【问题讨论】:
-
您确定图片链接正确吗?您编写了 Storage::get($id.'/'.$id.'.'.'jpeg');但您告诉我们您正在寻找 /storage/app/。不应该是 Storage::get('app/'.$id.'/'.$id.'.'.'jpeg'); ?
-
@CDF,感谢您的回复。路径是正确的。在 Laravel 5 存储方法中,默认路径是 storage/app/。我们可以编辑它(config/filesystems.php)。
-
好的,谢谢。我看到你用图片编辑了你的帖子。您还可以发布浏览器返回的标题吗?
-
@CDF,我更新了我的帖子。
-
你想把图片存入文件夹吗?