为什么在将数组转换为字符串时出错?

时间:2016-12-20 11:17:45

标签: php

for($i=0; $i<=count($_FILES['myfile']['name']); $i++)
{
    move_uploaded_file($_FILES['myfile']['tmp_name'][$i],"img/".$_FILES['myfile']['name'][$i]); //<!-- Error
    $path="img/".$_FILES['myfile']['name'];
}

2 个答案:

答案 0 :(得分:1)

我认为这一行很可能是你的问题

$path="img/".$_FILES['myfile']['name']

为其添加索引,就像上一行中对$_FILE的其他引用一样

for($i=0;$i<=count($_FILES['myfile']['name']);$i++) {
        move_uploaded_file($_FILES['myfile']['tmp_name'][$i],"img/".$_FILES['myfile']['name'][$i]); 
        $path="img/".$_FILES['myfile']['name'][$i];   //<- changed line
}

答案 1 :(得分:1)

将您的路径更改为以下内容:

$path="img/".$_FILES['myfile']['name'][$i];