user1033600
user1033600

Reputation: 289

multiple file upload codeigniter

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

Upvotes: 0

Views: 4840

Answers (1)

srbhbarot
srbhbarot

Reputation: 1317

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.

Upvotes: 8

Related Questions