CodeIgniter Forums
How uploading many files? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How uploading many files? (/showthread.php?tid=4031)



How uploading many files? - El Forum - 11-03-2007

[eluser]iniweb[/eluser]
Example i'am using File Class:

Code:
$this->load->library('upload', $this->config->config);
$this->upload->initialize($this->config->config);
$this->upload->do_upload('userfile', 'videofile');

Userfile - Image
Videofile - Media

But return only userfile:

Quote:Array ( [file_name] => drupal_ru.png [file_type] => image/png [file_path] => /home/yaba/html/uploads/images/ [full_path] => /home/yaba/html/uploads/images/drupal_ru.png [raw_name] => drupal_ru [orig_name] => [file_ext] => .png [file_size] => 130.66 [is_image] => 1 [image_width] => [image_height] => [image_type] => [image_size_str] => )



How uploading many files? - El Forum - 11-03-2007

[eluser]xwero[/eluser]
You can only validate/upload one file at the time using the upload class so you would have to do something like this
Code:
$fields = array('userfile','videofile');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']    = '100';
$config['max_width']  = '1024';
$config['max_height']  = '768';
$config2['upload_path'] = './uploads/';
$config2['allowed_types'] = 'avi|wmv|mov';
foreach($fields as $field)
{
   if(isset($_FILES[$field]))
   {
      switch($field)
      {
         case 'userfile':
           $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            // error
        }    
        else
        {
            // success
        }
           break;
         case 'videofile':
           $this->load->library('upload', $config2);
    
        if ( ! $this->upload->do_upload())
        {
            // error
        }    
        else
        {
            // success
        }
           break;
      }
   }
}

It's a bit messy but i think you get the picture.