I'm trying to get the error of my uploaded file but I get the following error :
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.';
}
I need to get the error code (1 to 8)
Your Boolean logic is incorrect, resulting in the elseif
block being called when there is no file. Try the following:
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.';
}
check if send file with enctype='multipart/form-data' in form sender