doujia7779 2017-04-10 16:35
浏览 16
已采纳

codeigniter db中缺少值文件名

I have a problem with update in my db the value of file upload

My controller

public function c_piloti_update()
    {
        // Modifica i valori scheda pilota
        $id= $this->input->post('id');
        $data = array(
            'nominativo' => $this->input->post('nominativo'),
            'fotografia' => $this->input->post('fotografia')
        );

        $config['upload_path']          = './uploads/avatar/';
        $config['allowed_types']        = 'gif|jpg|png';
        $config['max_size']             = 1000;


        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload('fotografia'))
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_form', $error);
        }
        else
        {
            $this->load->model('alfa/alfa_model');
            $this->piloti_model->alfa_update($id,$data);            
            redirect('alfa/alfa-edit/'.$id);        
        }

    }

My Model

public function alfa_update($id, $data)
{       
    $this->db->where('id', $this->input->post('id'));  
    $this->db->update('register', $data);  
}  

The attachment is saved, but in the DB i haven't the file name. thanks

  • 写回答

1条回答 默认 最新

  • dongxu2398 2017-04-10 17:50
    关注

    Get File details using this : $this->upload->data();

        if ( ! $this->upload->do_upload('fotografia'))
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_form', $error);
        }
        else
        {
            $data['image_name '] = $this->upload->data('file_name'); 
           //here image_name is column name in table
            $this->load->model('alfa/alfa_model');
            $this->piloti_model->alfa_update($id,$data);            
            redirect('alfa/alfa-edit/'.$id);        
        }
    

    see this :

    https://www.codeigniter.com/user_guide/libraries/file_uploading.html#the-upload-directory

    Change model method alfa_update() to this :

       public function alfa_update($id, $data)
       {       
         $this->db->where('id',$id);  
         $this->db->update('register', $data);  
       }  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看