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.

Zar
  • 6,786
  • 8
  • 54
  • 76
  • 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. – Philip Mar 23 '12 at 20:22
  • Answered it here: http://stackoverflow.com/questions/9276756/codeigniter-multiple-file-upload/36943949#36943949 – Rauli Rajande Apr 29 '16 at 17:09

2 Answers2

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

Woxxy
  • 1,313
  • 10
  • 12
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...

Mike Garcia
  • 2,051
  • 1
  • 14
  • 12