Php 如何重新订购$u文件(多次上载)阵列?
我正在改进一些上传页面,每次发送请求都要上传一个以上的文件。但是,我接收$\u文件数组的方式很复杂,我不能按照我的意愿使用它 基本上,对于上传的每个文件,我都要在数据库中保存一行,要做到这一点,我发现将每个分离的信息作为数组索引处理会更好。以下是我获得调试的方式:Php 如何重新订购$u文件(多次上载)阵列?,php,Php,我正在改进一些上传页面,每次发送请求都要上传一个以上的文件。但是,我接收$\u文件数组的方式很复杂,我不能按照我的意愿使用它 基本上,对于上传的每个文件,我都要在数据库中保存一行,要做到这一点,我发现将每个分离的信息作为数组索引处理会更好。以下是我获得调试的方式: Array ( [UploadDocumentoCentralAtendimento] => Array ( [name] => Array
Array
(
[UploadDocumentoCentralAtendimento] => Array
(
[name] => Array
(
[documentoCentralAtendimento] => Array
(
[0] => AntigoTratamentoDados.png
[1] => tratamentoDados.png
[2] => tratamentoDadosMeuConsignado.png
)
)
[type] => Array
(
[documentoCentralAtendimento] => Array
(
[0] => image/png
[1] => image/png
[2] => image/png
)
)
[tmp_name] => Array
(
[documentoCentralAtendimento] => Array
(
[0] => /tmp/phpHzKqiE
[1] => /tmp/phpnjGTRF
[2] => /tmp/php73hnrH
)
)
[error] => Array
(
[documentoCentralAtendimento] => Array
(
[0] => 0
[1] => 0
[2] => 0
)
)
[size] => Array
(
[documentoCentralAtendimento] => Array
(
[0] => 77067
[1] => 25496
[2] => 20898
)
)
)
)
以及我希望如何获得:
Array
(
[0] => Array
(
[name] => AntigoTratamentoDados.png
[tempName] => /tmp/phpP8lIN6
[type] => image/png
[size] => 77067
[error] => 0
)
[1] => Array
(
[name] => tratamentoDados.png
[tempName] => /tmp/phptzwJX8
[type] => image/png
[size] => 25496
[error] => 0
)
[2] => Array
(
[name] => tratamentoDadosMeuConsignado.png
[tempName] => /tmp/phpTySL7a
[type] => image/png
[size] => 20898
[error] => 0
)
)
这是我的HTML输入:
<input id="uploaddocumentocentralatendimento-documentocentralatendimento" class="form-field" name="UploadDocumentoCentralAtendimento[documentoCentralAtendimento][]" multiple="" type="file">
我尝试了一些递归策略,但没有一个对我有效。迭代其中一个子数组,并在同一个键下从其他子数组中收集值
$k
:
$newFiles = [];
foreach ($_FILES['UploadDocumentoCentralAtendimento']['name']['documentoCentralAtendimento'] as $k => $v) {
$newFiles[] = [
'name' => $v,
'type' => $_FILES['UploadDocumentoCentralAtendimento']['type']['documentoCentralAtendimento'][$k],
// etc
];
}
迭代其中一个子数组,并在同一个键下从其他子数组中收集值
$k
:
$newFiles = [];
foreach ($_FILES['UploadDocumentoCentralAtendimento']['name']['documentoCentralAtendimento'] as $k => $v) {
$newFiles[] = [
'name' => $v,
'type' => $_FILES['UploadDocumentoCentralAtendimento']['type']['documentoCentralAtendimento'][$k],
// etc
];
}
它确实起作用了,它是如此的简单以至于我很难过我不能认出哈哈。非常感谢你!它确实起作用了,它是如此的简单以至于我很难过我不能认出哈哈。非常感谢你!