0

How to do a multiple file upload in codeigniter

<input type="file" name="pic[]">
<input type="file" name="pic[]">
<input type="file" name="pic[]">

How can I upload this?

using the do_upload function

user1033600
  • 289
  • 4
  • 7
  • 17
  • 1
    See http://stackoverflow.com/questions/9845872/codeigniter-uploading-multiple-files-with-one-input/9846065#9846065 that I answered few days ago. – Woxxy Mar 26 '12 at 18:52
  • 1
    you can see this article of stackoverflow hope this can help you http://stackoverflow.com/questions/1908247/codeigniter-multiple-file-upload – Pus Mar 26 '12 at 18:58

1 Answers1

8

You can upload any number of files

$config['upload_path'] = 'upload/Main_category_product/';
$path=$config['upload_path'];
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1024';
$config['max_width'] = '1920';
$config['max_height'] = '1280';
$this->load->library('upload');

foreach ($_FILES as $key => $value)
{
     if (!empty($key['name']))
     {
         $this->upload->initialize($config);
         if (!$this->upload->do_upload($key))
         {
             $errors = $this->upload->display_errors();
             flashMsg($errors);    
         }
         else
         {
             // Code After Files Upload Success GOES HERE
         }
     }
}

You can see There is no need of name property.

Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
srbhbarot
  • 1,317
  • 12
  • 16
  • It not works for me so I used code from http://stackoverflow.com/questions/9903619/codeigniter-html5-trying-to-upload-multiple-images-at-once which worked for me. – Rohan Kumar Sep 09 '13 at 11:53