php - Update picture/image in Codeigniter -


i'm trying create update image user want change photo.the when click submit on photo upload, there no photo uploaded , photo's column still no update.

here contorller:

function foto($id='')     {         $data['data']        = $this->user_model->get_foto($id);         $data['form_action'] = site_url("user/update_foto/$id");         $this->load->view('user/foto_form', $data);     }      function update_foto($id=''){         $this->user_model->update_foto($id);     } 

here model:

function get_foto($id=0){         $id    = $this->session->userdata('id');         $sql   = "select id,foto user id= '$id'";         $query = $this->db->query($sql);         $data  = $query->row_array();         return $data;     }      function update_foto(){         $config['upload_path'] = './upload/';         $config['allowed_types'] = 'jpg|png|jpeg';         $this->load->library('upload', $config);         if (!$this->upload->do_upload('foto'))         {             $id_user=$this->session->userdata('id');             redirect ("user/foto/$id_user");         }   else {             $id_user=$this->session->userdata('id');             $data=array(             'foto'=>$this->input->post('foto')             );             $this->db->where('id',$id_user);             $this->db->update('user',$data);             redirect("user");         }     } 

and upload form on view:

    <form role="form" action="<?php echo $form_action ?>" class="form-horizontal style-form" method="post" enctype="multipart/form-data">     <label >upload foto</label>     <input type="file" name="foto"/>   <button type="submit">save</button>    </form> 

any answer? many answer...

on controller try replacing this

from

site_url("user/update_foto/$id"); 

to

site_url("user/update_foto") ./. $id; 

or use uri segment refer user guide.

site_url("user/update_foto") ./. $this->uri->segment(4); // unsure id check uri segment in url. 

your route may need changed

$route['user/update_foto/(:any)'] = "controllername/foto/$1";

all ways make sure controller has index()


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -