1

In my page , i have created one form with different fields like name, email,password,etc., now i have to upload the image and store in my database. any one send the code with all fields including image upload file. i have to try in many times, image can't upload in my database. my controller is

function activity()
    {
        $this->load->library('form_validation');
        //field name,error message, validation rules
        $this->form_validation->set_rules('activityid', 'Activity Id', 'trim|required');
        $this->form_validation->set_rules('hostid', 'Host Id', 'trim|required');
        $this->form_validation->set_rules('activityname', 'Activity Name', 'trim|required');
        $this->form_validation->set_rules('date', 'Date', 'trim|required');
        $this->form_validation->set_rules('venue', 'Venue', 'trim|required');
        $this->form_validation->set_rules('typeofactivity', 'Type of Activity', 'trim|required');
        $this->form_validation->set_rules('conductedby', 'Conducted By', 'trim|required');
         $config['upload_path'] = './asset/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);    
$w = $this->upload->data();
        if($this->form_validation->run()==FALSE)
        {
            //$this->load->view('signup_form');
            $this->activity_reg();
        }
        else
        {
             $this->load->model('membership_model');

            $query=$this->membership_model->activity();

            if($query)
            {

                $data['main_content']='signup_successful';
                $this->load->view('includes/templates',$data);
            }
            else
            {
                $this->load->view('activity');
            }
        }
    }

my model is

function activity()

    {
        $w = $this->upload->data();
        $new_member_insert_data= array(

                        'activityid'=>$this->input->post('activityid'),
                        'hostid'=>$this->input->post('hostid'),
                        'activityname'=>$this->input->post('activityname'),
                        'date'=>$this->input->post('date'),
                        'venue'=>$this->input->post('venue'),
                        'typeofactivity'=>$this->input->post('typeofactivity'),
                        'conductedby'=>$this->input->post('conductedby'),
                            'image' => $w['file_name']
            );

                        $this->load->database();
                        $insert=$this->db->insert('activity',$new_member_insert_data);
                        return $insert;

    }
6
  • what is the error you are getting from image upload library? Commented Feb 5, 2014 at 7:52
  • no error.data's only stored in my database, not store in image Commented Feb 5, 2014 at 7:57
  • do you want to store image or image name only? Commented Feb 5, 2014 at 7:58
  • i want store image in my db Commented Feb 5, 2014 at 8:04
  • did you try below solution? Commented Feb 5, 2014 at 8:09

1 Answer 1

1

Use file_get_contents() function.

$image = $_FILES['YOUR_INPUT_NAME']['tmp_name'];
$new_member_insert_data= array(
                    'activityid'=>$this->input->post('activityid'),
                    'hostid'=>$this->input->post('hostid'),
                    'activityname'=>$this->input->post('activityname'),
                    'date'=>$this->input->post('date'),
                    'venue'=>$this->input->post('venue'),
                    'typeofactivity'=>$this->input->post('typeofactivity'),
                    'conductedby'=>$this->input->post('conductedby'),
                    'image' => file_get_contents( $image )
        );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.