Monday 15 February 2010

php - Not Picking Up Image If False -



php - Not Picking Up Image If False -

in codeigniter form, trying set else if info image. picks if when image exists. need pick no_image.png, if no image exist using same code below.

<?php class users extends mx_controller { public function index() { $this->getform(); } protected function getform($user_id = 0) { $this->load->model('admin/user/users_model'); $user_info = $this->users_model->getuser($user_id); if (trim($this->input->post('image'))) { $data['image'] = $this->input->post('image'); } elseif (!empty($user_info)) { // location image works fine. $data['image'] = config_item('base_url') . 'image/catalog/' . $user_info['image']; } else { // should display if no image nowadays in database not work. $data['image'] = config_item('base_url') . 'image/'. 'no_image.png'; } } $this->load->view('user/users_form', $data); }

view page :

<div class="form-group"> <label for="input-image" class="col-lg-2 col-md-12 col-sm-2 col-xs-12"><?php echo $entry_image; ?></label> <div class="col-lg-10 col-md-10 col-sm-10 col-xs-12"> <a href="" id="thumb-image" data-toggle="image" class="img-thumbnail"> <img src="<?php echo $image; ?>"/> </a> </div> </div>

make sure in image folder no_image.png exists. , accessible directly.like , can seek straight open link in browser http://www.yoursiteurl/image/no_image.png.

if opens there 2 possibilities

in config file there no end slash baseurl.

the code never executes else block

if dierct link not open htaccess problem may exists.

hope help you.

or elseif status may this

elseif(!empty($user_info) && $user_info['image'] && file_exists(config_item('base_url') . 'image/catalog/' . $user_info['image'])){ ... } // + user info valid user image not available

php codeigniter

No comments:

Post a Comment