如何显示来自 storage/app 的用户图像?
How to display the user image from storage/app?
如何显示存储文件夹(public 之外)中的图像?我将图像文件存储在 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:更新方式对信息更新有效,对照片无效
您要么或需要:
1) 需要将图像保存在 storage/app/public
目录中 - 首先需要将存储路径符号链接到 public:
php artisan storage:link
那么你的方法应该行得通。
2) 创建到 return 图像的路径。
Route::get('show-image/{id}', function() {
$membre = Membre::findOrFail($id);
$file = storage_path($membre->photo);
return response()->file($file);
})
如何显示存储文件夹(public 之外)中的图像?我将图像文件存储在 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:更新方式对信息更新有效,对照片无效
您要么或需要:
1) 需要将图像保存在 storage/app/public
目录中 - 首先需要将存储路径符号链接到 public:
php artisan storage:link
那么你的方法应该行得通。
2) 创建到 return 图像的路径。
Route::get('show-image/{id}', function() {
$membre = Membre::findOrFail($id);
$file = storage_path($membre->photo);
return response()->file($file);
})