[ images] => Array
[ name] => Array
(
[0] = icon. jpeg
[1] => IMG_ 0105.JPG
)
[type] => Array
(
[0] => image/ jpeg
[1] = image/ jpeg
)
[tmp_ name] => Array
(
[0] => /Applicat ions/MAMP/ tmp/ php/ phpciVHd2
[1] => /Applications/MAMP/tmp/ php/ phpgIEJiz
)
[size] => Array(
[0] => 154741
[1] = 520101
)
//对不同结构的数据统一数据格式
private function format(): array
{
$files = [] ;
foreach ($_ FILES as $field) {
if (is_array($field[ 'name'])) {
foreach ($field['name'] as $id => $file) {
$files[] = [
'name' => $field['name'] [$id] ,
'type ' =>$field['type'] [$id],
'error' => $field['error'] [$id] ,
'tmp_ name' => $field['tmp_ name'] [$id] ,
'size' => $field['size'] [$id] ,
];
}
} else {
$files[] = $field;
}
}
return $files;
输出结果:
Array
(
[0] => Array
(
[name] => icon-s.jpg
[type] => image/ jpeg
[tmp_ name] =>_ /Applications/MAMP / tmp/ php/ phpFyvLQ9
[error] => 0
[size] => 55358
[1] => Array
[name] => icon. jpeg
[type] =>image/ jpeg
[error] => 0
[tmp_ name] => /Applications /MAMP/ tmp/ php/ phpXBmN27
[size] => 154741
[2] => Array
(
[name] => IMG_ 0105.JPG
[type] => image/ jpeg
[error] => 0
[tmp_ name] => /Appl ications /MAMP/ tmp/ php/ phpL4mGR2
[size] => 520101
)
)
|