1

I'm trying to upload several files at once from ONE input:

<input type="file" name="form-image[]" id="form-image" multiple="true" />

Which itself without CodeIgniter works fine. In my attempt to do the same thing with CodeIgniters file helper; I get an error (is_uploaded_file() expects parameter 1 to be string, array given), which indicates that I am doing something wrong, or CodeIgniter simply doesn't support multiple files?

My faulty code so far:

//Iterate through each file uploaded
for ($i = 0; isset($_FILES['form-image']['name'][$i]); $i++) {

   //Fix the settings
   $config['upload_path'] = "./static/vimmel/";
   $config['file_name'] = time() . rand(1,988);
   $config['allowed_types'] = 'gif|jpg|png';
   $config['max_size']  = '1024';
   $config['max_width']  = '1024';
   $config['max_height']  = '768';
   $this->load->library('upload', $config);

   //Do the upload
   $this->upload->do_upload("form-image")
}

Please note that I did edit out all error handling and such. Also note that I do not use the is_uploaded_file() function.

Appreciating all help and suggestions. Thanks.

2
  • Im not sure if CI supports multi file uploads, I would stick to your original approach if it works, really the clue is in the name "helper". If it is of no help to you, simply dont use it. Commented Mar 23, 2012 at 20:22
  • Answered it here: stackoverflow.com/questions/9276756/… Commented Apr 29, 2016 at 17:09

2 Answers 2

2

CodeIgniter doesn't support multiple files. Using the do_upload() in a foreach won't be different than using it outside.

You will need to deal with it without the help of CodeIgniter. Here's an example https://github.com/woxxy/FoOlSlide/blob/master/application/controllers/admin/series.php#L331-370

Sign up to request clarification or add additional context in comments.

Comments

1

I'm using an extension of the Upload library that includes a do_multiple_upload() function accepting an array of files

https://github.com/nicdev/CodeIgniter-Multiple-File-Upload

It lacks some error management (e.g. if one of your files doesn't have an allowed extension the whole upload fails), but you can change the returns for continues in the loop.

Hope it helps somebody...

Comments

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.