我正在尝试获取上传文件的错误,但是我收到以下错误:
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)
答案 0 :(得分: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.';
}
答案 1 :(得分:0)
检查表单发件人
中是否发送enctype ='multipart / form-data'的文件