2

我正在尝试获取上传文件的错误,但出现以下错误:

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.';
}

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

4

2 回答 2

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.';
}
于 2013-01-16T22:44:23.567 回答
0

检查是否在表单发件人中发送带有 enctype='multipart/form-data' 的文件

于 2013-01-16T22:45:35.127 回答