Last active
August 29, 2015 14:19
-
-
Save krmgns/f7a7402be712d51a88bb to your computer and use it in GitHub Desktop.
Normalize $_FILES returning assoc array.
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 | |
function normalizePostFiles(array $postFiles) { | |
$files = []; | |
if (isset($postFiles['tmp_name']) && is_array($postFiles['tmp_name'])) { | |
foreach ($postFiles['tmp_name'] as $i => $file) { | |
if (isset( | |
$postFiles['name'][$i], $postFiles['type'][$i], | |
$postFiles['size'][$i], $postFiles['error'][$i], | |
$postFiles['tmp_name'][$i] | |
)) { | |
$files[$i] = [ | |
'name' => $postFiles['name'][$i], | |
'type' => $postFiles['type'][$i], | |
'size' => $postFiles['size'][$i], | |
'error' => $postFiles['error'][$i], | |
'tmp_name' => $postFiles['tmp_name'][$i], | |
]; | |
} | |
} | |
} | |
return $files; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment