<form action="" method="post" enctype="multipart/form-data"> <input type="file" name="oneLevel[]"> <input type="file" name="oneLevel[]"> <input type="submit"> </form>
array( 'files' => array ( 'name' => array ( 0 => 'Lighthouse.jpg', 1 => 'Hydrangeas.jpg', ), 'type' => array ( 0 => 'image/jpeg', 1 => 'image/jpeg', ), 'tmp_name' => array ( 0 => '/tmp/phpQR67Qp', 1 => '/tmp/phpJjnAHA', ), 'error' => array ( 0 => 0, 1 => 0, ), 'size' => array ( 0 => 561276, 1 => 595284, ), ), )
/** * * * @param array $arrayForFill . * "" * $_FILES * @param string $currentKey * @param mixed $currentMixedValue * @param string $fileDescriptionParam * (name, type, tmp_name, error size) * @return void */ function rRestructuringFilesArray(&$arrayForFill, $currentKey, $currentMixedValue, $fileDescriptionParam) { if (is_array($currentMixedValue)) { foreach ($currentMixedValue as $nameKey => $mixedValue) { rRestructuringFilesArray($arrayForFill[$currentKey], $nameKey, $mixedValue, $fileDescriptionParam); } } else { $arrayForFill[$currentKey][$fileDescriptionParam] = $currentMixedValue; } } // , "" $_FILES $arrayForFill = array(); // foreach ($_FILES as $firstNameKey => $arFileDescriptions) { // , // foreach ($arFileDescriptions as $fileDescriptionParam => $mixedValue) { rRestructuringFilesArray($arrayForFill, $firstNameKey, $_FILES[$firstNameKey][$fileDescriptionParam], $fileDescriptionParam); } } // $_FILES $_FILES = $arrayForFill;
array( 'files' => array ( 0 => array ( 'name' => 'Lighthouse.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/tmp/phpKNqlsc', 'error' => 0, 'size' => 561276, ), 1 => array ( 'name' => 'Hydrangeas.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/tmp/phpB8X3E8', 'error' => 0, 'size' => 595284, ), ), )
Source: https://habr.com/ru/post/133072/
All Articles