Last active
February 9, 2022 08:04
-
-
Save ozgurg/c366b7033869016791345c85b76be926 to your computer and use it in GitHub Desktop.
PHP $_FILES Normalization (Single & Multiple)
This file contains 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 normalizeFiles() | |
{ | |
$files = []; | |
$multiple = false; | |
foreach($_FILES as $name => $fileArray) { | |
if(is_array($fileArray["name"])) { | |
$multiple = true; | |
foreach($fileArray as $attrib => $list) { | |
foreach($list as $index => $value) { | |
$files[$name][$index][$attrib] = $value; | |
} | |
} | |
} else { | |
$files[$name][] = $fileArray; | |
} | |
} | |
if(!$multiple && count($files) === 1) { | |
$files = array_map("current", $files); | |
} | |
return $files; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment