0

我有一点在 MAMP 上工作正常的代码,但在 WAMP 上给了我一个错误。代码是:

$uploads = ""; 
for($x=0; $x<$count_data; $x++)
{
    $uploads .= $_FILES['file']['name'][$x] . ' ';
}

错误是:

注意:未定义的偏移量:1

注意:未定义的偏移量:2

注意:未定义的偏移量:3

注意:未定义的偏移量:4

有任何想法吗?

这是文件上传代码:

$number_of_file_fields = 0;
$number_of_uploaded_files = 0;
$number_of_moved_files = 0;
$uploaded_files = array();
$upload_directory = dirname(__file__) . '/../uploads/'; //set upload directory
$count_data=count($_FILES['file']) ;
$uploads = ""; 
for($x=0; $x<$count_data; $x++)
{
    $uploads .= $_FILES['file']['name'][$x] . ' ';
}



for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
    $number_of_file_fields++;
    if ($_FILES['file']['name'][$i] != '') { //check if file field empty or not
        $number_of_uploaded_files++;
        $uploaded_files[] = $_FILES['file']['name'][$i];
        if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $upload_directory . $orderNumber . "_" . $_FILES['file']['name'][$i])) {
            $number_of_moved_files++;
        }
    }
}
4

1 回答 1

0

有两种方法可以将多个文件上传组织到$_FILES数组中,具体取决于它们是否具有相同的name属性。

要处理这两种情况,请尝试以下操作:

$uploads = '';
foreach ($_FILES as $inputName => $fileInfo) {
    foreach ((array) $fileInfo['name'] as $n) {
        $uploads .= $n . ' ';
    }
}

为了帮助调试两个主机之间的差异,请尝试$_FILES在每个主机上回显数组的内容,看看它有什么不同。

print_r($_FILES);
于 2013-06-06T23:41:31.293 回答