上传数据库中的Image目录

I want to upload image directory together with other data into the database when a submit button is clicked i want it to be able to upload all the data into a database. I want to upload the image together with student details The following is the structure of my files the upload controller function is in Admin files.

`The controller.

   function add_student(){

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

    $this->form_validation->set_error_delimiters('<div class="error">', '</div>');

    $this->form_validation->set_rules('fname', 'Student Firstname', 'required|min_length[2]|max_length[35]');

    $this->form_validation->set_rules('mname', 'Student Middlename', 'required|min_length[2]|max_length[35]');

    $this->form_validation->set_rules('lname', 'Student Lastname', 'required|min_length[2]|max_length[35]');

    $this->form_validation->set_rules('gender', 'Choose The Gender', 'required|min_length[2]|max_length[35]');

    $this->form_validation->set_rules('datepicker', 'Please pick a DOB', 'required|min_length[5]|max_length[15]');

    $this->form_validation->set_rules('marital', 'Please Enter Marital Status', 'required|min_length[5]|max_length[15]');

    $this->form_validation->set_rules('pob', 'Please Enter POB Residence', 'required|min_length[5]|max_length[15]');

    $this->form_validation->set_rules('pobdistrict', 'Please Enter The POB District', 'required|min_length[2]|max_length[15]');

    $this->form_validation->set_rules('pobregion', 'Please Enter The POB Region', 'required|min_length[5]|max_length[15]');


    $this->form_validation->set_rules('residence', 'Please Enter The Residence', 'required|min_length[5]|max_length[15]');

    $this->form_validation->set_rules('region', 'Please Enter The Region', 'required|min_length[5]|max_length[15]');

    $this->form_validation->set_rules('district', 'Please Enter The District', 'required|min_length[5]|max_length[15]');


    $this->form_validation->set_rules('education', 'Please Enter The Education Level', 'required|min_length[5]|max_length[30]');

    $this->form_validation->set_rules('phone', 'Please Enter The Education Level', 'required|min_length[5]|max_length[15]');




    if ($this->form_validation->run() == FALSE)
    {
        $this->load->model('fetch_data');

        $data['schoolname'] =$this->fetch_data->school_data();

        $data['partnername'] =$this->fetch_data->partner_data();

        $data['main_content'] = '/student/addstudent';

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

    }else{
        $config['upload_path'] = '../images/student_profile';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = "2048000"; // Can be set to particular file size , here it is 2 MB(2048 Kb)
        $config['max_height'] = "768";
        $config['max_width'] ="1024";
        $this->load->library('upload', $config);

        if(!$this->upload->do_upload()){
            $error = array('error' => $this->upload->display_errors());

            echo $error;

        }
        $data_upload_files = $this->upload->data();

        $image = $data_upload_files['full_path'];



        $data = array(
            'student_fname' => $this->input->post('fname'),
            'student_mname' => $this->input->post('mname'),
            'student_lname' => $this->input->post('lname'),
            'gender' => $this->input->post('gender'),
            'y_enrolled' => $this->input->post('datepicker'),
            'marital_status' => $this->input->post('marital'),
            'education' => $this->input->post('education'),

            'pob' => $this->input->post('pob'),
            'region' => $this->input->post('pobregion'),
            'district' => $this->input->post('pobdistrict'),

            'residence' => $this->input->post('residence'),
            'res_district' => $this->input->post('district'),

            'res_region' => $this->input->post('region'),
            'phone' => $this->input->post('phone'),

            'student_profile_img' => $image ,
        );


        // Transfering Data To Model

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

        $this->insert_data->student_data($data);

    }


}`


**The model**


` 
 public function student_data($data){

    $this->db->insert('student_profile', $data);
}`

Do you REALLY wants to insert BINARY data in your database? Trust me, you won't. You just have to save the path to the file!

If you really want to save it, transform your image in base64 then write it in your database.

$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);