Monday, 23 March 2015

How to image insert and update in codeigniter.

welcome.php(controller) insert
=========================
  function insert()    {        if(@$this->session->userdata('id'))        {            header("Location:".base_url()."/index.php/welcome/timeline");        }        else        {            $data=$_POST;            $this->load->model('reg_model','mod');            //image start            $config['upload_path']          = './uploads/'; //folder name            $config['allowed_types']        = 'gif|jpg|png';            $config['max_size']             = 1002322;            $config['max_width']            = 10242323;            $config['max_height']           = 768123123;
            $this->load->library('upload', $config);            if ( !$this->upload->do_upload('file')) //file name            {                $error =  $this->upload->display_errors();
            }            else            {                $imagedata = $this->upload->data();            }            $data['file']=$imagedata['file_name']; //file is  data base filed name
//end of image            $get=$this->mod->ins($data);            $sessi= $get['id'];            $this->session->set_userdata('id',$sessi);            $data=$this->session->userdata('id');            header("Location:" . base_url() . "/index.php/welcome/timeline");        }    }
================
insert (model) 
================ 
function ins($data){    $data['hob']=$data['hob'][0].','.$data['hob'][1];    $this->db->insert('rgistration',$data);    echo '<script>alert("insert Data");</script>';    header('location:http://localhost/CodeIgniter/index.php/welcome');}

===============
 welcome.php (connroller) update
================
function alluserupdate($data1){
   $data=$_POST;    $data['hob']=$data['hob'][0].','.$data['hob'][1];  //$ses=$this->session->userdata('id');    $config['upload_path']          = './uploads/'; //folder name    $config['allowed_types']        = 'gif|jpg|png';    $config['max_size']             = 1002322;    $config['max_width']            = 10242323;    $config['max_height']           = 768123123;    $this->load->library('upload', $config);    if ( !$this->upload->do_upload('file')) //file name    {        $error =  $this->upload->display_errors();    }    else    {        $imagedata = $this->upload->data();    }

   // $imagedata['file_name']=$data['file']; //file is  data base filed name    $data['file']=$imagedata['file_name'];      $this->load->model('reg_model','mod');    $this->mod->updateq1($data,$data1);
    header("location:" .base_url()."/index.php/welcome/adminuserpro");}
==============
update in model imag 
===============
//update data    function updateq1($data,$data1)    {//        echo '<pre>';//        print_r($data1);//        die;        $this->db->where('id',$data1);        $this->db->set($data);        $this->db->update('rgistration');    }
 

No comments:

Post a Comment