无法在codeigniter中将图像路径插入数据库

时间:2018-02-19 10:11:24

标签: codeigniter controller

class Stud_controller extends CI_Controller {

function __construct(){

parent::__construct();

$this->load->helper('url');

$this->load->database();

}

public function index()

{

$query = $this->db->get("stud");

$data['records'] = $query->result();

$this->load->helper('url');

$this->load->view('Stud_view',$data);

}

public function add_student_view()

{

$this->load->helper('form');

$this->load->view('Stud_add');

}

public function add_student()

{

$this->load->helper('form');

$this->load->library('form_validation');

$this->load->model('Stud_Model');

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

  $config['upload_path']          = './uploads/';

  $target_file['image'] = $config['upload_path'] . basename($_FILES["fileToUpload"]["name"]);

                $config['allowed_types']        = 'gif|jpg|jpeg|png|pdf|doc';

                $config['max_size']             = 1000;

                $config['max_width']            = 1300;

                $config['max_height']           = 1024;

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

                if ( ! $this->upload->do_upload('fileToUpload'))

{

                   echo "fail";

                    //$this->load->view('upload', $error);

                }

                else

                {

                   echo "success";

                   echo  $target_file['image'] ;


                   //$QueryInsertFile="INSERT INTO stud SET image='$target_file'";

                   // $this->load->view('success', $data);

                }

$data = array(

'roll_no' => $this->input->post('roll_no'),

'name' => $this->input->post('name'),

$target_file['image'] =>$data['image']

);

$this->Stud_Model->insert($data);

$query = $this->db->get("stud");

$data['records'] = $query->result();

$this->load->view('Stud_view',$data);

}

public function update_student_view(){

$this->load->helper('form');

$roll_no = $this->uri->segment('3');

$query = $this->db->get_where("stud",array("roll_no"=>$roll_no));

$data['records'] = $query->result();

$data['old_roll_no'] = $roll_no;

$this->load->view('Stud_edit',$data);

}

public function update_student(){

$this->load->model('Stud_Model');

$data = array(

'roll_no' => $this->input->post('roll_no'),

'name' => $this->input->post('name')

);

$old_roll_no = $this->input->post('old_roll_no');

$this->Stud_Model->update($data,$old_roll_no);

$query = $this->db->get("stud");

$data['records'] = $query->result();

$this->load->view('Stud_view',$data);

}

public function delete_student(){

$this->load->model('Stud_Model');

$roll_no = $this->uri->segment('3');

$this->Stud_Model->delete($roll_no);

$query = $this->db->get("stud");

$data['records'] = $query->result();

$this->load->view('Stud_view',$data);

}

}

1 个答案:

答案 0 :(得分:0)

这一行是错误

$ target_file [' image'] => $ data [' image']

替换成

'图像' = GT; $ _ TARGET_FILE ['图像]