[英]Images are not loading
I have some code to change user image . 我有一些代码可以更改用户图像 。 But after changing it I have to press
control+shift+R
to see changes. 但是更改后,我必须按
control+shift+R
来查看更改。
I changed File::delete()
to unlink()
. 我将
File::delete()
更改为unlink()
。 But it did not work. 但这没有用。
Controller code: 控制器代码:
public function index(){
$id = Auth::id();
$info = Admin::select('name', 'login', 'image')-
>where('id', $id)->first();
return view('admin.index')->with('info', $info);
}
public function changes(Request $request){
$this->validate($request,[
'name' => 'required',
'login' => 'required',
]);
$login = Auth::user()->login;
$admin = Admin::where('login', $login)->first();
if($admin){
$admin->name = $request['name'];
$admin->login = $request['login'];
if(!is_null($request['old_password']) and !is_null($request['new_password'])){
$this->validate($request,[
'new_password' => 'required',
'old_password' => 'required',
]);
if(Hash::check($request['old_password'], Auth::user()->password)){
$new_password = Hash::make($request['new_password']);
$admin->password = $new_password;
}
}
if(!is_null($request['profile_image'])){
$this->validate($request,[
'profile_image' => 'image|mimes:jpeg,png,jpg',
]);
if (!is_null(Auth::user()->image)) {
$admin_image = public_path() .'/'. Auth::user()->image;
if((File::exists($admin_image))){
File::delete($admin_image);
}
}
$image = $request->file('profile_image');
$image_extension = $image->getClientOriginalExtension();
$image_name= Auth::id() .'.'. $image_extension;
$image->move(public_path('admin_assets/assets/images/users'), $image_name);
$admin->image = $image_name;
}
$admin->save();
}
return redirect()->route('admin.index');
}
I think I should refresh public folder in index action, but how? 我认为我应该在索引操作中刷新公用文件夹,但是如何?
If the new image has the same URL
(same name and path in your case) of the old image the browser uses the old image that has in his own cache. 如果新的图像具有相同的
URL
的旧有形象的(相同的名称和路径,你的情况)浏览器使用的是在他自己的高速缓存中的旧形象。
The best solutions for this issue, apart asking the user to press Ctrl+F5
(or Ctrl+Shift+R
) to clear the page cache , are: 除了要求用户按
Ctrl+F5
(或Ctrl+Shift+R
)清除页面缓存之外,此问题的最佳解决方案是:
?v=2
) to the image URL
to force the browser to request the new image: the URL
is different from everything it has in cache so it's forced to get the new resource. URL
上附加一个版本化的查询字符串 (类似于?v=2
),以强制浏览器请求新图像:该URL
与缓存中的所有内容都不相同,因此被迫获取新资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.