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

Php 使用codeigniter将图像路径插入数据库,php,codeigniter,Php,Codeigniter,这是我的控制器插入代码 此代码将图像插入到图像路径文件夹中,但该路径未保存在数据库中 function add_hotel() { //validate form input $this->form_validation->set_rules('hotelname', 'Hotel Name', 'required|xss_clean'); $this->form_validation->set_rules('hotellocation

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

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');
                }
function add_hotel(){
//验证表单输入
$this->form_validation->set_规则('hotelname','hotelname','required'xss_clean');
$this->form_validation->set_规则('hotellocation','hotellocation','required'xss_clean');
$this->form_validation->set_规则('hotelphone','hotelphone','required'xss_clean');
$this->form_validation->set_rules('hotelimg'、'hotelimage'、'callback_Image_upload');
$this->form_validation->set_规则('hotelabout'、'hotelabout'、'required'xss_clean');
如果($this->form\u 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”;
如果(!$this->upload->do\u upload($field\u name))
{
$error=array('error'=>$this->upload->display_errors());
$this->load->view('admin/add_hotel',$error);
}
否则{
$data=数组(
'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'))
);
打印(数据);
$this->db->insert('hotel_content',$data);
$this->session->set_flashdata('message',“酒店添加成功。

”; 重定向(base_url().'index.php/admin/hotel_controller/index'); }
显示的错误是:

遇到PHP错误
严重性:注意
消息:数组到字符串的转换
文件名:mysql/mysql\u driver.php
电话号码:552

发生数据库错误:

错误号码:1054
“字段列表”中的未知列“数组”
插入“hotel_内容”('hotelname','hotellocation','hotelphone','hotelimg','hotelabout')值('hotel5','hyd','0402365477',数组,'welcome')
文件名:G:\wamp\www\CodeIgniter\system\database\DB\u 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{
$data=数组(
'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'))
);
打印(数据);
$this->db->insert('hotel_content',$data);
$this->session->set_flashdata('message',“酒店添加成功。

”; 重定向(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{
$image_path=$this->upload->data();
$data=数组(
'hotelname'=>this->input->post('hotelname'),
'hotellocation'=>this->input->post('hotellocation'),
“hotelphone”=>this->input->post('hotelphone'),
'hotelimg'=>$image\u path[完整路径],
'hotelabout'=>$this->input->post('hotelabout'))
);
打印(数据);
$this->db->insert('hotel_content',$data);
$this->session->set_flashdata('message',“酒店添加成功。

”; 重定向(base_url().'index.php/admin/hotel_controller/index'); }
else部分中的行“$this->upload->data('hotelimg')”返回一个数组。 您只需要从中上传路径,该路径可以提取为:

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