framework/web/MultipartFormDataParser.php
private function addFile(&$files, $name, $info)
    {
        if (strpos($name, '[') === false) {
            $files[$name] = $info;
            return;
        }

        $fileInfoAttributes = [
            'name',
            'type',
            'size',
            'error',
            'tmp_name',
            'tmp_resource',
        ];

        $nameParts = preg_split('/\\]\\[|\\[/s', $name);
        $baseName = array_shift($nameParts);
        if (!isset($files[$baseName])) {
            $files[$baseName] = [];
            foreach ($fileInfoAttributes as $attribute) {
                $files[$baseName][$attribute] = [];
            }
        } else {
            foreach ($fileInfoAttributes as $attribute) {
                $files[$baseName][$attribute] = (array) $files[$baseName][$attribute];
            }
        }

        foreach ($fileInfoAttributes as $attribute) {
            if (!isset($info[$attribute])) {
                continue;
            }

            $current = &$files[$baseName][$attribute];
            foreach ($nameParts as $namePart) {
                $namePart = trim($namePart, ']');
                if ($namePart === '') {
                    $current[] = [];
                    $keys = array_keys($current);
                    $lastKey = array_pop($keys);
                    $current = &$current[$lastKey];
                } else {
                    if (!isset($current[$namePart])) {
                        $current[$namePart] = [];
                    }
                    $current = &$current[$namePart];
                }
            }
            $current = $info[$attribute];
        }
    }
private function addFile(&$files, $name, $info)
    {
        if (strpos($name, '[') === false) {
            $files[$name] = $info;
            return;
        }

        $fileInfoAttributes = [
            'name',
            'type',
            'size',
            'error',
            'tmp_name',
            'tmp_resource',
        ];

        $nameParts = preg_split('/\\]\\[|\\[/s', $name);
        $baseName = array_shift($nameParts);
        if (!isset($files[$baseName])) {
            $files[$baseName] = [];
            foreach ($fileInfoAttributes as $attribute) {
                $files[$baseName][$attribute] = [];
            }
        } else {
            foreach ($fileInfoAttributes as $attribute) {
                $files[$baseName][$attribute] = (array) $files[$baseName][$attribute];
            }
        }

        foreach ($fileInfoAttributes as $attribute) {
            if (!isset($info[$attribute])) {
                continue;
            }

            $current = &$files[$baseName][$attribute];
            foreach ($nameParts as $namePart) {
                $namePart = trim($namePart, ']');
                if ($namePart === '') {
                    $current[] = [];
                    $keys = array_keys($current);
                    $lastKey = array_pop($keys);
                    $current = &$current[$lastKey];
                } else {
                    if (!isset($current[$namePart])) {
                        $current[$namePart] = [];
                    }
                    $current = &$current[$namePart];
                }
            }
            $current = $info[$attribute];
        }
    }
private function addFile ( & $ files , $ name , $ info ) { if ( strpos ( $ name , '[' ) === false ) { $ files [ $ name ] = $ info ; return ; } $ fileInfoAttributes = [ 'name' , 'type' , 'size' , 'error' , 'tmp_name' , 'tmp_resource' , ] ; $ nameParts = preg_split ( '/\\]\\[|\\[/s' , $ name ) ; $ baseName = array_shift ( $ nameParts ) ; if ( ! isset ( $ files [ $ baseName ] ) ) { $ files [ $ baseName ] = [ ] ; foreach ( $ fileInfoAttributes as $ attribute ) { $ files [ $ baseName ] [ $ attribute ] = [ ] ; } } else { foreach ( $ fileInfoAttributes as $ attribute ) { $ files [ $ baseName ] [ $ attribute ] = ( array ) $ files [ $ baseName ] [ $ attribute ] ; } } foreach ( $ fileInfoAttributes as $ attribute ) { if ( ! isset ( $ info [ $ attribute ] ) ) { continue ; } $ current = & $ files [ $ baseName ] [ $ attribute ] ; foreach ( $ nameParts as $ namePart ) { $ namePart = trim ( $ namePart , ']' ) ; if ( $ namePart === '' ) { $ current [ ] = [ ] ; $ keys = array_keys ( $ current ) ; $ lastKey = array_pop ( $ keys ) ; $ current = & $ current [ $ lastKey ] ; } else { if ( ! isset ( $ current [ $ namePart ] ) ) { $ current [ $ namePart ] = [ ] ; } $ current = & $ current [ $ namePart ] ; } } $ current = $ info [ $ attribute ] ; } }
Adds file info to the uploaded files array by input name, e.g. `Item[file]`.
@param array $files array containing uploaded files
@param string $name input name specification.
@param array $info file info.
Adds file info to the uploaded files array by input name e . g . Item [ file ] .