开启辅助访问
帐号登录 |立即注册

PHP实现多维数组的重整,处理不同类型的上传数据

 
[ 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
)
)




回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

友情链接
  • 艾Q网

    提供设计文章,教程和分享聚合信息与导航工具,最新音乐,动漫,游戏资讯的网站。