Загрузка нескольких файлов (массив) с помощью CodeIgniter 2.0
Это моя форма
Код: Выделить всё
Title * :
Description :
Image :
Save
Код: Выделить всё
public function add_estates()
{
$data['page_title'] = "© IDEAL - Administrator - Real State - Add Real Estate";
$data['main_content'] = 'admin/add_estates';
if ($this->input->post() !== FALSE) {
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'Career Title', 'trim|required');
if ($this->form_validation->run() !== FALSE) {
$title = $this->input->post('title');
$description = $this->input->post('description');
if (!empty($_FILES['images']['name'][0])) {
if ($this->upload_files($title, $_FILES['images']) === FALSE) {
$data['error'] = $this->upload->display_errors('', '');
}
}
if (!isset($data['error'])) {
$this->admin_model->add_estate($title, $description, $image_name);
$this->session->set_flashdata('suc_msg', 'New real estate added successfully');
redirect('admin/add_estates');
}
}
}
$data['suc_msg'] = $this->session->flashdata('suc_msg');
$this->load->view('layout_admin', $data);
}
Код: Выделить всё
private function upload_files($title, $files)
{
$config = array(
'upload_path' => './upload/real_estate/',
'allowed_types' => 'jpg|gif|png',
'overwrite' => 1,
);
$this->load->library('upload', $config);
foreach ($files['name'] as $key => $image) {
$_FILES['images']['name']= $files['name'][$key];
$_FILES['images']['type']= $files['type'][$key];
$_FILES['images']['tmp_name']= $files['tmp_name'][$key];
$_FILES['images']['error']= $files['error'][$key];
$_FILES['images']['size']= $files['size'][$key];
$config['file_name'] = $title .'_'. $image;
$this->upload->initialize($config);
if ($this->upload->do_upload($image)) {
$this->upload->data();
} else {
return false;
}
}
return true;
}
Подробнее здесь: https://stackoverflow.com/questions/201 ... odeigniter
Мобильная версия