如何显示存储文件夹(公共外部)中的图像?我将图像文件存储在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方法适用于信息更新,但不适用于照片。
发布于 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);
})
https://stackoverflow.com/questions/55329683
复制相似问题