0

I want to check if file upload is empty or not, but it just goes one way.. Always empty. here's what I have.

if(isset($_FILES) && @$_FILES['file_upload']['error'] != '4'){
    //Upload file then insert ticket info to database
}else{
    //Just insert info to database
}

it always goes to the if statement whether the file field is empty or not.

6
  • maybe this will help you: stackoverflow.com/questions/43417033/… Commented Apr 20, 2017 at 8:31
  • Thanks, I'm looking into it Commented Apr 20, 2017 at 8:39
  • I am guessing your input type file attribute name is mismatch. Commented Apr 20, 2017 at 9:11
  • @teshvenk Here's my input type name <input type="file" name="file_upload[]" multiple /> Commented Apr 20, 2017 at 9:12
  • @TheTruth Since it is multiple file upload you have have to use like $_FILES['file_upload']['error'][0] Commented Apr 20, 2017 at 11:07

1 Answer 1

1

Should be:

if ($_FILES['file_upload']['error'] !== 4){
  //Upload file then insert ticket info to database
} else {
    //Just insert info to database
}

Simple method is (recommend):

if (empty($_FILES['userfile']['name'])) { 
   //Upload file then insert ticket info to database
} else {
    //Just insert info to database
}
Sign up to request clarification or add additional context in comments.

3 Comments

No, it's not :( sadly
Try: var_dump(empty($_FILES['userfile']['name']) and post an error was receive in your question.
it doesn't return anything

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.