使用codeigniter将数据保存在数据库中

时间:2016-01-16 10:36:29

标签: codeigniter

我想将图像与我的其他数据(如idnumber,name等)结合起来。我仍然对如何操作感到困惑,但我可以将其保存到文件夹和数据库但我无法显示< / p>

class Addstudent extends CI_Controller { 
     function indexes(){

          if($this->session->userdata('logged_in'))
        {
            $session_data = $this->session->userdata('logged_in');

            $data['Username'] = $session_data['Username'];
            $this->load->view('addstudentinformation',$data);
        } else{
            redirect('welcome', 'refresh');
        }
           if((!isset($session_data) || $session_data !=TRUE)) {

            redirect('welcome', 'refresh');
        }
    }
     function do_upload(){
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['overwrite'] = TRUE;
    $config['remove_spaces'] = TRUE;
    $config['max_size'] = '100';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';
    $this->upload->initialize($config);

        $this->form_validation->set_rules('Firstname', 'First name', 'trim|required');
        $this->form_validation->set_rules('Middlename', 'Middle name', 'trim|required');
        $this->form_validation->set_rules('Lastname', 'Last name', 'trim|required');
        $this->form_validation->set_rules('Idnumber', 'Id number', 'trim|required');
        $this->form_validation->set_rules('Religion', 'Religion', 'trim|required');
        $this->form_validation->set_rules('Mothertongue', 'Mother tongue', 'trim|required');
        $this->form_validation->set_rules('Cellnumber', 'Cell number', 'trim|required');
        $this->form_validation->set_rules('Age', 'Age', 'trim|required');
        $this->form_validation->set_rules('Birthday', 'Birthday', 'trim|required');
        $this->form_validation->set_rules('Sex', 'Sex', 'trim|required');
        $this->form_validation->set_rules('Password', 'Password', 'trim|required');
        $this->form_validation->set_rules('Fillform', 'Fill form', 'trim|required');
        $this->form_validation->set_rules('Yearlevel', 'Year level', 'trim|required'); 


        $this->form_validation->set_rules('Province', 'Province', 'trim|required');
        $this->form_validation->set_rules('Town', 'Town', 'trim|required');
        $this->form_validation->set_rules('Barrio', 'Barrio', 'trim|required');
        $this->form_validation->set_rules('Permanentaddress', 'Permanent Address', 'trim|required');
        $this->form_validation->set_rules('Contactemergency', 'Middlename', 'trim|required');
        $this->form_validation->set_rules('Contactnumber', 'Contact number', 'trim|required');


        if ($this->form_validation->run() == FALSE){



            $this->indexes();
        }
        else{
       $images =   file_get_contents($_FILES['FileToUpload']['tmp_name']);  
            $images = "FileToUpload";
           $this->upload->do_upload($images);

        array('upload_data' =>  $this->upload->data());


           $data= array(
                        'Firstname' => $this->input->post('Firstname'),
                        'Middlename' => $this->input->post('Middlename'),
                        'Lastname' => $this->input->post('Lastname'),
                                                'Idnumber' => $this->input->post('Idnumber'),
                        'Religion' => $this->input->post('Religion'),
                        'Mothertongue' => $this->input->post('Mothertongue'),
                                                'Cellphonenumber' => $this->input->post('Cellnumber'),
                        'Age' => $this->input->post('Age'),
                        'Dateofbirth' => $this->input->post('Birthday'),
                                                'Sex' => $this->input->post('Sex'),
                        'Password' => $this->input->post('Password'),
                        'Datefilled' => $this->input->post('Fillform'),
                                                'Yearlevel' => $this->input->post('Yearlevel'),

                                        'Imageupload'=> $images,

                        'Province' => $this->input->post('Province'),
                                                'Town' => $this->input->post('Town'),
                        'Barrio' => $this->input->post('Barrio'),
                        'Permanentaddress' => $this->input->post('Permanentaddress'),
                                                'Contactperson' => $this->input->post('Contactemergency'),
                        'Contactpersonnumber' => $this->input->post('Contactnumber'),


                    ); 
            $this->db->insert('studentinformation',$data);
           redirect('educationalbackground/index', refesh); 

        }


    }

这就是用数据库查看的方式

  <img alt="uploaded image" src="<?php echo base_url( 'uploads/'. $r-> Imageupload)  ?>">

0 个答案:

没有答案