simple question
what is the meaning and purpose of this:
if($_FILES)
thanks, cheers!
simple question
what is the meaning and purpose of this:
if($_FILES)
thanks, cheers!
It is a way to check if files were uploaded during the request (via <input type="file">
in a form or similar). When files are uploaded, information about those files is stored in the $_FILES variable, which is an array. If no files are uploaded the array is empty and if ($_FILES)
would not fire (since an empty array cast to a boolean is false
). If files are uploaded the array would contain values and if ($_FILES)
would fire (since any non-empty array cast to a boolean is true
).
Better would be (IMHO): if (count($_FILES) > 0)
(because I don’t like implicit casting)