How to check if the file input field is empty?

Mohamed Hassan picture Mohamed Hassan · Apr 10, 2012 · Viewed 69k times · Source

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?

Answer

Mohamed Hassan picture Mohamed Hassan · Sep 5, 2012
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
}