我有几个文件输入字段,每个文件输入都有一个公用名和唯一名。唯一名用于某些验证目的。
<input name="file12 ftr_file_uploads[]" class="multi_files file " type="file">
<input name="file10 ftr_file_uploads[]" class="multi_files file " type="file">
<input name="file10 ftr_file_uploads[]" class="multi_files file " type="file">
...............
尝试以php表单提交方式上载文件时,
$u文件的内容如下。
array(2) {
["file1_ftr_file_uploads"]=> array(5)
{ ["name"]=> array(1) { [0]=> string(13) "Jellyfish.jpg" }
["type"]=> array(1) { [0]=> string(10) "image/jpeg" }
["tmp_name"]=> array(1) { [0]=> string(14) "/tmp/phpx7iId2" }
["error"]=> array(1) { [0]=> int(0) }
["size"]=> array(1) { [0]=> int(775702) } }
["file2_ftr_file_uploads"]=> array(5)
{ ["name"]=> array(1) { [0]=> string(12) "Penguins.jpg" }
["type"]=> array(1) { [0]=> string(10) "image/jpeg" }
["tmp_name"]=> array(1) { [0]=> string(14) "/tmp/phpN6QWoD" }
["error"]=> array(1) { [0]=> int(0) }
["size"]=> array(1) { [0]=> int(777835) } }
}
数组键名更改为文件输入字段的串联名称。
ftr_file_uploads
而不是
fileIDnumber_ftr_file_uploads
.
我做了如下的事情。
foreach($_FILES as $keyval=>$value)
{
$_FILES['ftr_file_uploads'] = $_FILES[$keyval];
$_FILES['ftr_file_uploads'][] mentioned in the answer
unset($_FILES[$keyval]);
}
当我这样使用的时候,我得到了这样的结果。
array(1) {
["ftr_file_uploads"]=>
array(5) {
["name"]=>
array(1) {
[0]=>
string(14) "Lighthouse.jpg"
}
["type"]=>
array(1) {
[0]=>
string(10) "image/jpeg"
}
["tmp_name"]=>
array(1) {
[0]=>
string(14) "/tmp/phpLdslxb"
}
["error"]=>
array(1) {
[0]=>
int(0)
}
["size"]=>
array(1) {
[0]=>
int(561276)
}
}
}
我需要这样的结果。
array(1) {
["ftr_file_uploads"]=>
array(5) {
["name"]=>
array(2) {
[0]=>
string(14) "Hydrangeas.jpg"
[1]=>
string(5) "w.jpg"
}
["type"]=>
array(2) {
[0]=>
string(10) "image/jpeg"
[1]=>
string(10) "image/jpeg"
}
["tmp_name"]=>
array(2) {
[0]=>
string(14) "/tmp/phpKMwmH1"
[1]=>
string(14) "/tmp/phpwwHU9G"
}
["error"]=>
array(2) {
[0]=>
int(0)
[1]=>
int(0)
}
["size"]=>
array(2) {
[0]=>
int(595284)
[1]=>
int(879394)
}
}
}