gpt4 book ai didi

php - 文件上传返回 "undefined index"错误

转载 作者:行者123 更新时间:2023-12-02 05:17:45 25 4
gpt4 key购买 nike

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

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)

最佳答案

您的 bool 逻辑不正确,导致 elseif block 在没有文件时被调用。尝试以下操作:

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

关于php - 文件上传返回 "undefined index"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14369239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com