-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilenormalizer.php
More file actions
40 lines (38 loc) · 954 Bytes
/
filenormalizer.php
File metadata and controls
40 lines (38 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace shgysk8zer0\DOMValidator;
trait FileNormalizer
{
final public static function getFiles()
{
// @see https://php.net/manual/en/features.file-upload.multiple.php#118180
$files = array();
foreach ($_FILES as $name => $values) {
// init for array_merge
if (!isset($files[$name])) {
$files[$name] = array();
}
if (!is_array($values['error'])) {
// normal syntax
$files[$name] = $values;
} else {
// html array feature
foreach ($values as $fileInfoKey => $subArray) {
$files[$name] = array_replace_recursive($files[$name], self::_fileWalker($subArray, $fileInfoKey));
}
}
}
return $files;
}
final private static function _fileWalker(Array $arr, $fileInfokey)
{
$ret = array();
foreach ($arr as $k => $v) {
if (is_array($v)) {
$ret[$k] = \call_user_func("self::". __FUNCTION__, $v, $fileInfokey);
} else {
$ret[$k][$fileInfokey] = $v;
}
}
return $ret;
}
}