2

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)

2 Answers 2

5

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.';
}
Sign up to request clarification or add additional context in comments.

Comments

0

check if send file with enctype='multipart/form-data' in form sender

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.