function addexample() { // When I click Submit.
$this->load->helper(array('form', 'url','text'));
$this->load->library('upload');
$data = array(
'example_name' => $this->input->post('example_name'),
'example_address' => $this->input->post('example_address'),
'example_image_1' => $this->input->post('example_image_1'),
'... some more fields',
'example_image_2' => $this->input->post('example_image_2'),
'... some more fields',
'example_image_3' => $this->input->post('example_image_3')
);
$this->db->insert('exampletable', $data);
///// Now uploading the 3 images files
// Creating folder
$lastID = $this->db->insert_id();
$slug = url_title(convert_accented_characters($this->input->post('example_name')), 'dash', TRUE);
$folderName = $lastID.'-'.$slug;
$pathToUpload = './assets/upload/files/examples/' . $folderName;
if (!file_exists($pathToUpload)) $create = mkdir($pathToUpload, 0777); // Folder is created.
//Uploading files to folder
// > I don't understand exactly how does it work and this part give me error.
$tempFile = $_FILES['file']['tmp_name'];
$fileName = $_FILES['file']['name'];
$targetPath = getcwd() . $pathToUpload.'/';
$targetFile = $targetPath . $fileName;
move_uploaded_file($tempFile, $targetFile);
}