Search code examples
phpvalidationfile-uploadinput-field

How to check if the file input field is empty?


I am having a hard time using $_FILES

I want to check if file upload field is empty or not then apply a condition such that if file upload is empty then the script doesn't try uploading the file. How do I enforce this?


Solution

  • if($_FILES["file"]["error"] != 0) {
    //stands for any kind of errors happen during the uploading
    } 
    

    also there is

    if($_FILES["file"]["error"] == 4) {
    //means there is no file uploaded
    }