gpt4 book ai didi

php - 使用 HTML5 和 PHP 加载多个文件

转载 作者:太空狗 更新时间:2023-10-29 13:39:17 25 4
gpt4 key购买 nike

我正在尝试使用 HTML5 加载多个文件。这是我在某个网站上找到的代码。在 PHP 代码中,它不将其识别为数组。

我做错了什么吗?谁能告诉我一个可行的解决方案?

谢谢。

index.html

<form action='save.php' method='post' enctype='multipart/form-data'>
<input name="uploads" type="file" multiple="multiple" />
<input type='submit' value="Upload File">
</form>

保存.php

function GetFiles() {
$files = array();
$fdata = $_FILES["uploads"];
if (is_array($fdata["name"])) {//This is the problem
for ($i = 0; $i < count($fdata['name']); ++$i) {
$files[] = array(
'name' => $fdata['name'][$i],
'tmp_name' => $fdata['tmp_name'][$i],
);
}
} else {
$files[] = $fdata;
}

foreach ($files as $file) {
// uploaded location of file is $file['tmp_name']
// original filename of file is $file['file']
}
}

最佳答案

你需要做一些名字的数组:

<input name="uploads[]" type="file" multiple="multiple" />

就像您过去使用复选框时所做的那样。

关于php - 使用 HTML5 和 PHP 加载多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3981149/

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