Tags down


php change profile image

By : Dezmund Jaxx
Date : May 04 2020, 05:09 PM

I have code to change user profile image. But after changing it I have to press control+shift+R to see changes.

I changed File::delete() to 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){
        'name'         => 'required',
        'login'        => 'required',
    $login = Auth::user()->login;
    $admin =  Admin::where('login', $login)->first();


        $admin->name = $request['name'];
        $admin->login = $request['login'];
        if(!is_null($request['old_password']) and !is_null($request['new_password'])){
                '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;
                'profile_image'         => 'image|mimes:jpeg,png,jpg',

            if (!is_null(Auth::user()->image)) {

                $admin_image = public_path() .'/'. Auth::user()->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;

    return redirect()->route('admin.index');

I think I should refresh public folder in index action, but how to do?

Answer :

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.

The best solutions for this problem, apart asking the user to press Ctrl+F5 (or Ctrl+Shift+R) to clear the page cache, are:

  1. Change name to the image each time the user changes the image itself.
  2. Append a versioned querystring (something like ?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.

Share : facebook icon twitter icon
Related Posts Related Posts :
  • clear array after form submit
  • pass url variable to javascript
  • access data using api
  • div position fixed css
  • add horizontal line between two div
  • disable toggle button css
  • css fixed line height
  • background image not working
  • table cell border
  • text line break css
  • overlay div on div
  • text direction rtl css
  • javascript convert string to an object
  • bind inner div click to outer div
  • jquery ajax oncomplete
  • how to use promise in for loop
  • jquery get element using variable
  • javascript send textbox value
  • pass div class content to another class or id
  • css new line after element
  • css calc not working properly
  • link disabled jquery
  • sql join table to subquery
  • MS Access SQL Issue with OR AND Operators
  • set textarea value using php
  • php merge two arrays into one
  • php form with google captcha
  • update current row in php
  • php date format mysql
  • mysql pdo select query
  • php function return an array
  • PHP mysqldump database to sql file
  • display image query
  • php create array using foreach loop
  • associative array php
  • group_concat in mysql laravel
  • php array_push empty
  • mysql on update cascade not working
  • pdo insert prepared statement
  • mysql insert ignore vs on duplicate key
  • mysql insert into existing row
  • mysql multi insert query
  • mysql group by show all rows
  • combine multiple arrays into one array php
  • how to sum values in an array
  • how to get sum of the total time
  • How to Create Facebook live stream without notification using API ?
  • on button click make div visible
  • css affect another element on hover
  • insert line after paragraph word
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org