多文件上传
<input type="file" name="file[]" multiple />
<?php
function reArrayFiles(&$file_post) {
$file_ary = array();
$file_count = count($file_post['name']);
$file_keys = array_keys($file_post);
for ($i=0; $i<$file_count; $i++) {
foreach ($file_keys as $key) {
$file_ary[$i][$key] = $file_post[$key][$i];
}
}
return $file_ary;
}
?>
打印 $_FILES
--------
array(1) {
["file"]=>
array(5) {
["name"]=>
array(5) {
[0]=>
string(20) "06_avatar_middle.jpg"
[1]=>
string(44) "7e3e6709c93d70cf7086f212ffdcd100baa12bb4.jpg"
[2]=>
string(20) "57U58PIC47y_1024.jpg"
}
["type"]=>
array(5) {
[0]=>
string(10) "image/jpeg"
[1]=>
string(10) "image/jpeg"
[2]=>
string(10) "image/jpeg"
}
["tmp_name"]=>
array(5) {
[0]=>
string(53) "C:UsersAdministratorAppDataLocalTempphpE364.tmp"
[1]=>
string(53) "C:UsersAdministratorAppDataLocalTempphpE3D2.tmp"
[2]=>
string(53) "C:UsersAdministratorAppDataLocalTempphpE431.tmp"
}
["error"]=>
array(5) {
[0]=>
int(0)
[1]=>
int(0)
[2]=>
int(0)
}
["size"]=>
array(5) {
[0]=>
int(202387)
[1]=>
int(168931)
[2]=>
int(116158)
}
}
}
---------
处理
$filesArr = reArrayFiles($_FILES['file']);
处理后
打印 $filesArr
-----------
array(3) {
[0]=>
array(5) {
["name"]=>
string(20) "06_avatar_middle.jpg"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(53) "C:UsersAdministratorAppDataLocalTempphp5E0E.tmp"
["error"]=>
int(0)
["size"]=>
int(202387)
}
[1]=>
array(5) {
["name"]=>
string(44) "7e3e6709c93d70cf7086f212ffdcd100baa12bb4.jpg"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(53) "C:UsersAdministratorAppDataLocalTempphp5E9B.tmp"
["error"]=>
int(0)
["size"]=>
int(168931)
}
[2]=>
array(5) {
["name"]=>
string(20) "57U58PIC47y_1024.jpg"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(53) "C:UsersAdministratorAppDataLocalTempphp5EFA.tmp"
["error"]=>
int(0)
["size"]=>
int(116158)
}
}