2

I am trying to upload multiple images.

My form is this:

<form>
  <input type="file" name="images[]">
  <input type="file" name="images[]">
  <input type="file" name="images[]">
</form>

I know that this form is right. I am getting an error when Codeigniter tries to upload a file.

function do_upload_images() {
    $files = $_FILES;

    $cpt = count ( $_FILES ['images'] ['name'] );
    for($i = 0; $i < $cpt; $i ++) {

        $_FILES ['images'] ['name'] = $files ['images'] ['name'] [$i];
        $_FILES ['images'] ['type'] = $files ['images'] ['type'] [$i];
        $_FILES ['images'] ['tmp_name'] = $files ['images'] ['tmp_name'] [$i];
        $_FILES ['images'] ['error'] = $files ['images'] ['error'] [$i];
        $_FILES ['images'] ['size'] = $files ['images'] ['size'] [$i];

        $this->upload->initialize ( $this->set_upload_options () );
        $this->upload->do_upload ($_FILES['images']);
    }
}
private function set_upload_options() {
    // upload an image options
    $config = array ();
    $config ['upload_path'] = './uploads/estate_images';
    $config ['allowed_types'] = 'gif|jpg|png';
    $config ['encrypt_name'] = TRUE;

    return $config;
}

This is the error i got:

Message: Illegal offset type in isset or empty Filename: libraries/Upload.php Line Number: 377

2
  • stackoverflow.com/questions/12615489/… Commented Feb 26, 2015 at 12:56
  • As we can return an array of data, all information files uploads? Commented Feb 27, 2016 at 3:03

1 Answer 1

5

I get the solution by myself. Just needed to change the following line:

$this->upload->do_upload ($_FILES['images']);

to

$this->upload->do_upload ('images');
Sign up to request clarification or add additional context in comments.

2 Comments

Is it really working ?! do_upload() seems expecting string not an array ?!
As we can return an array of data, all information files uploads?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.