gpt4 book ai didi

php - 在 PHP 中转换数组 ($_FILES)

转载 作者:行者123 更新时间:2023-12-01 22:44:31 24 4
gpt4 key购买 nike

我想在这样的数组中处理多个文件上传 $_FILES

foreach ($_FILES as $file) {
// do stuff...
// $file['name'] and as such
}

但是数组看起来像这样

Array ( 
[name] => Array (
[0] => 2010-10-04_205047.jpg
[1] =>
[2] =>
)

[type] => Array (
[0] => image/jpeg
[1] =>
[2] =>
)

[tmp_name] => Array (
[0] => E:\localhost\tmp\php118.tmp
[1] =>
[2] =>
)

[error] => Array (
[0] => 0
[1] => 4
[2] => 4
)

[size] => Array (
[0] => 92127
[1] => 0
[2] => 0
)
)

如何把它做成我想要的格式的数组?

谢谢

最佳答案

这很麻烦,但是

$_MYFILES = array();
foreach(array_keys($_FILES['name']) as $i) { // loop over 0,1,2,3 etc...
foreach(array_keys($_FILES) as $j) { // loop over 'name', 'size', 'error', etc...
$_MYFILES[$i][$j] = $_FILES[$j][$i]; // "swap" keys and copy over original array values
}
}

关于php - 在 PHP 中转换数组 ($_FILES),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4203398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com