Codeigniter:Update Image and Display

后端 未结 2 1822
孤城傲影
孤城傲影 2021-01-03 12:11

I\'m stuck on a problem with updating image. I\'ve created image upload which works fine but I also want it to be updated. When I add a need image it updates correctly but I

2条回答
  •  無奈伤痛
    2021-01-03 12:34

        public function update()
        {
            $id=$this->input->post("id");
    
            $s_em=$this->input->post("s_em");
            $s_na=$this->input->post("s_na");
    
    
     if($_FILES[file]['name']!="")
                {
        $config['upload_path'] = './uploads/';
            $config['allowed_types'] =     'gif|jpg|png|jpeg|jpe|pdf|doc|docx|rtf|text|txt';
            $this->load->library('upload', $config);
            if ( ! $this->upload->do_upload('file'))
            {
                $error = array('error' => $this->upload-   >display_errors());
            }
            else
            {
                $upload_data=$this->upload->data();
                $image_name=$upload_data['file_name'];
            }
        }
        else{
                    $image_name=$this->input->post('old');
                }
    $data=array('s_em'=>$s_em,'s_na'=>$s_na,'file'=>$image_name);
    $this->Students_m->db_update($data,$id);
    }
    

    in the view file add the following

    
    

    try this..let me know this works or not.

提交回复
热议问题