使用codeigniter将图像的路径插入数据库


Inserting path of a image into database using codeigniter

这是我的控制器插入代码
此代码将图像插入图像路径文件夹,但该路径未保存在数据库中。

function add_hotel() {
      //validate form input
      $this->form_validation->set_rules('hotelname', 'Hotel Name', 'required|xss_clean');
      $this->form_validation->set_rules('hotellocation', 'Hotel Location', 'required|xss_clean');
      $this->form_validation->set_rules('hotelphone', 'Hotel Phone', 'required|xss_clean');
      $this->form_validation->set_rules('hotelimg', 'Hotel Image ', 'callback__image_upload');
      $this->form_validation->set_rules('hotelabout', 'Hotel About', 'required|xss_clean');
      if ($this->form_validation->run() == true)
      {     
         $config['upload_path'] = './images/';
         $config['allowed_types'] = 'gif|jpg|png';
         $config['max_size']    = '1000000';
         $config['overwrite'] = TRUE;
         $config['remove_spaces'] = TRUE;
         $config['encrypt_name'] = FALSE;
         $this->load->library('upload', $config);
         $field_name = "hotelimg";
         if ( ! $this->upload->do_upload($field_name))
                {
         $error = array('error' => $this->upload->display_errors());
         $this->load->view('admin/add_hotel', $error);
                    }
    else {
        $data = array(
            'hotelname'             => $this->input->post('hotelname'),
            'hotellocation'     => $this->input->post('hotellocation'),
            'hotelphone'            => $this->input->post('hotelphone'),
            'hotelimg'      =>    $this->upload->data('hotelimg'),
            'hotelabout'            => $this->input->post('hotelabout')
                );
            print_r($data);
            $this->db->insert('hotel_content', $data);
            $this->session->set_flashdata('message', "<p>Hotel added successfully.</p>");
            redirect(base_url().'index.php/admin/hotel_controller/index');
                }

显示的错误为:

遇到PHP错误
严重性:通知
消息:数组到字符串的转换
文件名:mysql/mysql_driver.php
线路编号:552

发生数据库错误:

错误编号:1054
"字段列表"中的未知列"数组">
插入"hotel_content"("hotelname"、"hoteplocation"、"Hotellphone"、"HOTLIMG"、"hotelabout"(值("hotel 5"、"hyd"、《0402365477》、《Array》、《welcome》(
文件名:G:''wamp''www''CodeIgniter''system''database''DB_driver.php
线路编号:330

我需要在数据库中插入路径。有人能帮我吗?

用替换其他部件

else {
            $data = array(
                'hotelname'             => $this->input->post('hotelname'),
                'hotellocation'     => $this->input->post('hotellocation'),
                'hotelphone'            => $this->input->post('hotelphone'),
                'hotelimg'      =>    $this->upload->data('hotelimg'),
                'hotelabout'            => $this->input->post('hotelabout')
            );
            print_r($data);
            $this->db->insert('hotel_content', $data);
            $this->session->set_flashdata('message', "<p>Hotel added successfully.</p>");
            redirect(base_url().'index.php/admin/hotel_controller/index');
            }

用这个

else {
            $image_path = $this->upload->data();
            $data = array(
                'hotelname'                => $this->input->post('hotelname'),
                'hotellocation'        => $this->input->post('hotellocation'),
                'hotelphone'             => $this->input->post('hotelphone'),
                'hotelimg'      =>    $image_path[full_path],
                'hotelabout'              => $this->input->post('hotelabout')
            );
            print_r($data);
            $this->db->insert('hotel_content', $data);
            $this->session->set_flashdata('message', "<p>Hotel added successfully.</p>");
            redirect(base_url().'index.php/admin/hotel_controller/index');
            }

else部分的行"$this->upload->data('hotelimg'("返回一个数组。你只需要上传路径,可以提取为:

$temp = $this->upload->data('hotelimg');
$uploadedPath = $temp[full_path];