0
My code is saving only an X image that I select in the input file, for example, if I select 3 or 10, only 1 image will be saved, I’ve tried everything and I can’t get it to save all the images in the folder...
public function add_multiple_images($images, $id, $resize = array('width' => 700, 'height' => 450)) {
$total_images = count($_FILES['files']['name']);
for ($i = 0; $i < $total_images; $i++) {
if ($_FILES['files']['name'][$i] !== '') {
$_FILES['files']['name'] = $_FILES['files']['name'][$i];
$_FILES['files']['type'] = $_FILES['files']['type'][$i];
$_FILES['files']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
$_FILES['files']['error'] = $_FILES['files']['error'][$i];
$_FILES['files']['size'] = $_FILES['files']['size'][$i];
$config = array();
$config['upload_path'] = "assets/uploads/locations/" . $id . "/";
$config['allowed_types'] = '*';
$config['max_size'] = '0';
$config['file_name'] = random_name();
$config['overwrite'] = FALSE;
$this->upload->initialize($config);
$this->upload->do_upload('files');
$upload_data = $this->upload->data();
if ($resize) {
$config['image_library'] = 'gd2';
$config['source_image'] = $upload_data['full_path'];
// $config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = $resize['width'];
$config['height'] = $resize['height'];
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear();
}
}
}
}
Form
<form id="form_add_img_location" method="POST" action="<?= base_url('Admin/add_images_locations'); ?>" enctype="multipart/form-data">
<input type="file" id="files" name="files[]" multiple>
</form>