首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何显示存储/app中的用户镜像?

如何显示存储/app中的用户镜像?
EN

Stack Overflow用户
提问于 2019-03-25 07:50:45
回答 1查看 51关注 0票数 0

如何显示存储文件夹(公共外部)中的图像?我将图像文件存储在storage/usernamee中,但无法在视图中显示它。如何将上传移动到"storage/images/“(文件夹名称为”images“下)?

视图

<form class="forms-sample" method="post" action="/updateprofil" enctype="multipart/form-data">
    @method('put')
    @csrf
    <div align="center">
        <img alt="User Pic" src="{{  storage_path($membre->photo) }}" id="profile-image1"
             class="img-circle img-responsive">
        <input id="pic" class="hidden" name="pic" type="file" accept="image/*">
        <div style="color:#999;">click here to change profile image</div>
    </div>
    <input type="hidden" id="idMembre" name="membre_id" value="{{  $membre->id }}">
</form>

控制器

public function updateprofil(Request $request)
{
    $request->validate(['cin' => 'size:8']);

    if ($request->hasFile('pic')) {
        $image = $request->file('pic');
        $filename = time() . '.' . $image->getClientOriginalExtension();
        Image::make($image)->resize(300, 300)->save(storage_path("app/usernamee/" . $filename));
        $request->pic = $filename;
    }

    $membre = Membre::findOrFail($request->membre_id);
    $membre->photo = 'app/usernamee/' . $request->pic;
    $membre->update($request->all());

    return redirect('profil');
}

This is my view of user profile

PS: update方法适用于信息更新,但不适用于照片。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-25 08:51:41

您或需要执行以下操作:

1)需要将镜像保存在公有目录下--首先需要将存储路径符号链接到storage/app/public

php artisan存储:链接

那么你的方法应该行得通。

2)创建返回镜像的路由。

Route::get('show-image/{id}', function() {
   $membre = Membre::findOrFail($id);

   $file = storage_path($membre->photo);

   return response()->file($file);
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55329683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档