如何显示存储文件夹中的图像(外部公共)?我将图像文件存储在 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');
}
PS:update 方法适用于信息更新,但不适用于照片。