CodeIgniter Forums
upload library with dynamic $_FILES - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: upload library with dynamic $_FILES (/showthread.php?tid=28856)



upload library with dynamic $_FILES - El Forum - 03-23-2010

[eluser]Dennis_gull[/eluser]
Hi,

I'm trying to upload a dynamic number of files but It seems like the upload library won't support it, does anyone know if there's a solution for this?

Example:
Code:
<input type="file" name="img[]" />
<input type="file" name="img[]" />

This would then result in an array like this:
Code:
array(5) {
  ["name"]=>
  array(2) {
    [0]=>
    string(23) "file1.png"
    [1]=>
    string(26) "file2.png"
  }
  ["type"]=>
  array(2) {
    [0]=>
    string(9) "image/png"
    [1]=>
    string(9) "image/png"
  }
  ["tmp_name"]=>
  array(2) {
    [0]=>
    string(23) "C:\wamp\tmp\php8EBB.tmp"
    [1]=>
    string(23) "C:\wamp\tmp\php8EBC.tmp"
  }
  ["error"]=>
  array(2) {
    [0]=>
    int(0)
    [1]=>
    int(0)
  }
  ["size"]=>
  array(2) {
    [0]=>
    int(187753)
    [1]=>
    int(197073)
  }
}



upload library with dynamic $_FILES - El Forum - 03-23-2010

[eluser]Dennis_gull[/eluser]
Solved it by creating a new function in MY_Upload file which will reformat the array so I later on can loop through it:

Code:
function split_files($input = 'userfile')
{
    $tmp = array();
        
        foreach($_FILES[$input] as $key => $data)
        {
            
            foreach($data as $i => $name)
            {
                $tmp[$i][$key] = $name;
            }
        }
        
    $_FILES = $tmp;
}