在代码点火器控制器中上传图像


uploading image in codeigniter controller

我无法在函数add()中使用代码行上传图像

只是为我提供一些上传图像的解决方案

公共函数 add() {

    if ($this->input->server('REQUEST_METHOD') === 'POST')
    {

        $this->form_validation->set_rules('image', 'image', 'required');
        $this->form_validation->set_rules('text', 'text', 'required');
        $this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>');

        if ($this->form_validation->run())
        {
            **$data_to_insert = array(
                'image' => $this->input->post('image'),
                'text' => $this->input->post('text'),**
            );
            if($this->home_banner_model->insert_home_banner($data_to_insert)){
                $data['flash_message'] = TRUE; 
            }else{
                $data['flash_message'] = FALSE; 
            }
        }
    }
    $data['main_content'] = 'admin/home_banner/add';
    $this->load->view('includes_admin/template', $data);  
}       
   $config = array(
        'upload_path'   =>  'uploadPath',
        'allowed_types' =>  'jpg,jpeg',
        'max_size'      =>  1500
    );
    $this->load->library('upload', $config);

        if(isset($_FILES['field_name']) && $_FILES[field_name]['name'] != NULL)
            if($this->upload->do_upload('field_name'))
            {
              $upload_data = $this->upload->data();
                $data_to_insert = array(
                    'attachment_link'   => 'uploadPath/'.$upload_data['file_name'],
                    'attachment_size'   => $upload_data['file_size']
                     // u can add parameters as for ur table to save
                    );
                $this->home_banner_model->insert_home_banner($data); 
            }
            else
            {
               echo $this->upload->display_errors();
            }