php - How to display a new image right away after successfully uploaded? -


enter image description here

i implemented logo upload system. take effect right away. require me refresh page see effect. i'm wondering how stop that.

img

<img id="userlogo" src="/images/account/operator/logo.png" alt="" class="thumbnail img-responsive"> 

form

{!! form::open(array('url' => '/profile/logo/update', 'class' => 'form-horizontal', 'role' =>'form','id' => 'editlogo','files'=>true)) !!}  <input name="logo_path" type="file"> <br><br>   <button class="btn btn-success btn-sm mr5" type="file"><i class="fa fa-user"></i> update logo</button>  {{ csrf_field() }} {!! form::close();!!} 

controller

public function updatelogo(){      $inputs = input::all();     $logo_path = array('logo_path' => input::file('logo_path'));      $rule =  ['logo_path' => 'max:100|mimes:jpeg,bmp,png'];      $id = auth::user()->account_id;     $type = auth::user()->account_type;      $validator = validator::make($logo_path, $rule );      if ( $validator->fails()) {         return redirect::to('/profile/')->witherrors($validator)->withinput();     } else {          $old_logo_path        = public_path().'/images/account/operator/logo.png';         $delete = file::delete($old_logo_path);          if (input::hasfile('logo_path'))         {              $file            = input::file('logo_path');             $destinationpath = public_path().'/images/account/operator/';             $uploadsuccess   = $file->move($destinationpath, 'logo.png');          }          return redirect::to('/profile/')         ->with('success','your company logo updated succesfully!');      } } 

result

my file got saved place want them be. when old logo still showing on page unless, refresh page, then, i'll see new one.

any hints / suggestions on appreciated !

this because image cached in browser, , since updating image same name browser shows cached image. hence better , effective solution have unique file name every time upload image or can append querystring image path every time serve image.

<img id="userlogo" src="/images/account/operator/logo.png?q=<?php echo microtime(); ?>" alt="" class="thumbnail img-responsive"> 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -