Reputation: 11
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;
}
Upvotes: 1
Views: 1989
Reputation: 43
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 )
);
Upvotes: 1