文件上载返回"未定义的索引"错误

Gmo*_*ake 2 php file-upload

我试图得到我上传的文件的错误,但我收到以下错误:

if(isset($_FILES['fichier']) && $_FILES['fichier']['error'] == 0)
{
        //do stuff here, no problem
}

    //get an error on this line "Notice: Undefined index: fichier in .."
elseif($_FILES['fichier']['error'] != 0)
{

}
else
{
    echo 'no file selected or an error occured with the page.';
}
Run Code Online (Sandbox Code Playgroud)

我需要获取错误代码(1到8)

cmb*_*ley 5

您的布尔逻辑不正确,导致在elseif没有文件时调用块.请尝试以下方法:

if (isset($_FILES['fichier'])) {

    // we know we have a file; do our error checking.
    if ($_FILES['fichier']['error'] == 0) {
        // do stuff here, no problem
    } else {
        // handle the error
    }
} else {
    echo 'no file selected or an error occured with the page.';
}
Run Code Online (Sandbox Code Playgroud)