I want to upload multiple images in one submit ,here i want to save the image name in two seperate fields in database . The code given below is i used for inserting single image. I tried to solve this by repeating the image upload code twice by changing the names and it works but i want to know is there any proper way to solve this.
<input type="file" class="upload" name="picture" />
public function image_upload()
{
if($this->input->post('submit')=="save")
{
//Check whether user upload picture
if(!empty($_FILES['picture']['name']))
{
$config['upload_path'] = 'uploads/images/banner/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['file_name'] = $_FILES['picture']['name'];
//Load upload library and initialize configuration
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('picture'))
{
$uploadData = $this->upload->data();
$picture = $uploadData['file_name'];
}
//Prepare array of user data
$userData = array('package_name' => $this->input->post('package_name'),'picture' => $picture);
//Pass user data to model
$insertUserData = $this->gt_banner_model->insert_image($userData);
}
//Storing insertion status message.
if(isset($insertUserData))
{
$data['message']="* Image inserted successfully.";
}
else
{
$data['message']="* Some problems occured, please try again.";
}
}
//Form for adding user data
$query = $this->db->get("gt_banner");
$data['records'] = $query->result();
$this->load->view('admin/banner/banner_insert',$data);
}