Last active
June 1, 2017 08:21
-
-
Save widoz/24221a7e1fab73f79714c62b485110d9 to your computer and use it in GitHub Desktop.
Form Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Re Order Files | |
* | |
* @since ${SINCE} | |
* @access private | |
* | |
* @param array $list An array $_FILES like to re-order | |
* | |
* @return array The re-order array list | |
*/ | |
private function reOrderFiles($list) | |
{ | |
$newList = array(); | |
/* | |
* If we are validating multiple files let's reorder them. | |
* By default the $_FILES structure is: | |
* | |
* [ | |
* 'name' => [ | |
* 0 => 'filename', | |
* 1 => 'filename', | |
* ], | |
* 'type' => [ | |
* 0 => 'mimetype', | |
* 1 => 'mimetype', | |
* ] | |
* etc.... | |
* ] | |
* | |
* We want to have the list ordered by index. | |
*/ | |
foreach ($list as $name => $item) { | |
// Is multiple? | |
if (is_array($item['name'])) { | |
$numCicle = count($item['name']); | |
$keys = array_keys($list[$name]); | |
$internalCounter = count($keys); | |
for ($c = 0; $c < $numCicle; ++$c) { | |
for ($ic = 0; $ic < $internalCounter; ++$ic) { | |
$newList[$name][$c][$keys[$ic]] = $list[$name][$keys[$ic]][$c]; | |
} | |
} | |
} else { | |
$newList[$name] = $item; | |
} | |
} | |
return $newList; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment