CodeIgniter Forums

Full Version: problem with image after upload , dosent display
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys
I`m having problem with showing image after it upload successfully , on local host everything works fine , but when i upload my code to test it online i`m facing this problem .
after my upload image or delete image success i set flash data for message and redirect with refresh method to show the image or place holder if its empty. (as i said it working like charm on local) But on server it needs several refreshesh or even ctrl F5 for image to take place .
controller :
Code:
public function do_upload(){
        $userid = $this->session->userdata('user_id');
        $this->deleteimage($userid);
        $result = parent::zz('./img/userprofilepix',TRUE);
        if($result[1] == 'error') {
                $this->session->set_flashdata('error', $result[0]);
                redirect('admin/users/upload');
                } else {
                $data['img'] = $result ;
                $this->ion_auth->update($userid, $data) ;
                $this->session->set_flashdata('error',
                '<div class="alert alert-success"><i class="icon-info-sign"></i>user pix has been saved </div>');
                redirect('admin/users/profile' , 'refresh');
            }
    }

View :
Code:
<div>
   <?php if($user->img == ''){ ?>
      <img class="centerized saye" src="<?= base_url()?>/public/img/icons/avator.jpg"><img />
   <?php } else { ?>
      <img class="centerized saye" src="<?= base_url()?>/img/userprofilepix/thumb/<?= $user->img; ?>"><img />
   <?php } ?>
</div>
(01-11-2015, 10:01 AM)shariaty Wrote: [ -> ]Hi guys
I`m having problem with showing image after it upload successfully , on local host everything works fine , but when i upload my code to test it online i`m facing this problem .
after my upload image or delete image success i set flash data for message and redirect with refresh method to show the image or place holder if its empty. (as i said it working like charm on local) But on server it needs several refreshesh or even ctrl F5 for image to take place .
controller :

Code:
public function do_upload(){
$userid = $this->session->userdata('user_id');
$this->deleteimage($userid);
$result = parent::zz('./img/userprofilepix',TRUE);
if($result[1] == 'error') {
$this->session->set_flashdata('error', $result[0]);
redirect('admin/users/upload');
} else {
$data['img'] = $result ;
$this->ion_auth->update($userid, $data) ;
$this->session->set_flashdata('error',
'<div class="alert alert-success"><i class="icon-info-sign"></i>user pix has been saved </div>');
redirect('admin/users/profile' , 'refresh');
}
}

View :

Code:
<div>
  <?php if($user->img == ''){ ?>
     <img class="centerized saye" src="<?= base_url()?>/public/img/icons/avator.jpg"><img />
  <?php } else { ?>
     <img class="centerized saye" src="<?= base_url()?>/img/userprofilepix/thumb/<?= $user->img; ?>"><img />
  <?php } ?>
</div>


i cant find the object "$user" from which user are accessing the "img" in the do_upload controller
i expected to see something like this:
$data['user] = something
$this->load->view('your view',$data);
This way, the "user" object will be passed directly to the view by the controller "do_upload" and you can access the "img" property from the "user" object

when you "redirect" to another controller, which has no reference of $data['user'], then you wont be able to access the properties $user. unless you set "user" object in session userdata