Welcome Guest, Not a member yet? Register   Sign In
upload library with dynamic $_FILES
#1

[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)
  }
}
#2

[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;
}




Theme © iAndrew 2016 - Forum software by © MyBB