Создать библиотеку для этого кода и звонить с контроллера
for($i = 0; $i < $config_array['files_count']; $i++)
{
if($config_array['file_data']['name'][$i])
{
$file_name = $config_array['file_data']['name'][$i];
$file_info = pathinfo($file_name);
$new_file_name = preg_replace('/[[:space:]]+/', '_', $file_info['filename']);
$new_file_name = $new_file_name.'_'.DATE(UPLOAD_FILE_DATE_FORMAT);
$new_file_name = str_replace('.','_',$new_file_name);
$file_extension = $file_info['extension'];
$new_file_name = $new_file_name.'.'.$file_extension;
$_FILES['attchment']['name'] = $new_file_name;
$_FILES['attchment']['tmp_name'] = $config_array['file_data']['tmp_name'][$i];
$_FILES['attchment']['error'] = $config_array['file_data']['error'][$i];
$_FILES['attchment']['size'] = $config_array['file_data']['size'][$i];
$config['upload_path'] = $config_array['file_upload_path'];
$config['file_name'] = $new_file_name;
$config['allowed_types'] = $config_array['file_permission'];
$config['file_ext_tolower'] = TRUE;
$config['remove_spaces'] = TRUE;
$config['max_size'] = $config_array['file_size'];
$this->CI->load->library('upload',$config);
$this->CI->upload->initialize($config);
if($this->CI->upload->do_upload('attchment'))
{
array_push($file_array,array(
'og_name'=> $file_name,
'name'=> $new_file_name)
);
}
else
{
array_push($error_msgs,$this->CI->upload->display_errors('',''));
}
}
}