Php 如何防止代码中出现未定义的偏移通知?

Php 如何防止代码中出现未定义的偏移通知?,php,upload,undefined,offset,Php,Upload,Undefined,Offset,注意:第6行未定义的偏移量:3 第6行如下: $tmpFilePath = $_FILES['file']['tmp_name'][$i]; 以下是您需要的全部信息: session_start(); //Loop through each file for($i=0; $i<count($_FILES['file']); $i++) { //Get the temp file path $tmpFilePath = $_FILES['file']['tmp_name'][$i]

注意:第6行未定义的偏移量:3

第6行如下:

$tmpFilePath = $_FILES['file']['tmp_name'][$i];
以下是您需要的全部信息:

session_start();
//Loop through each file
for($i=0; $i<count($_FILES['file']); $i++) {
  //Get the temp file path
  $tmpFilePath = $_FILES['file']['tmp_name'][$i];

  //Make sure we have a filepath
  if ($tmpFilePath != ""){
    //Setup our new file path
    $newFilePath = "./uploaded_files/" . $_FILES['file']['name'][$i];

    //Upload the file into the temp dir
    if(move_uploaded_file($tmpFilePath, $newFilePath)) {

    echo "Upload Successful!<br />";

}
}
}
session_start();
//循环浏览每个文件

对于($i=0;$i检查它是否存在:

if (isset($_FILES['file']['tmp_name'][$i]))
{
    $tmpFilePath = $_FILES['file']['tmp_name'][$i];
}

乍一看,for()循环中的代码应该是:

for($i=0; $i<count($_FILES['file']['tmp_name']); $i++)

看到了吗?

我们需要更多的代码来帮助您。通过这段代码,我只能猜测$I中整数的索引不存在……我添加了更多。这应该给您足够的时间来处理。您认为可以帮助吗?即使只是因为代码工作得很好而取消了通知,我也无法在任何时候显示它有人上传了一些东西。表单真的上传了不止一个文件吗?如果不是这样,for循环就没有多大意义。可能的重复导致了更多的问题。事实上,没有我的错误,我在输入代码时做了一些错误。这很有效,感谢这不是一个解决方案。。从不令人惊讶的通知,而是修复通知。
for($i=0; $i<count($_FILES['file']['tmp_name']); $i++)  
$tmpFilePath   =   $_FILES['file']['tmp_name'][$i];