You can check by using the size
field on the $_FILES
array like so:
if ($_FILES['cover_image']['error'] == 4 || ($_FILES['cover_image']['size'] == 0 && $_FILES['cover_image']['error'] == 0))
{
// cover_image is empty (and not an error), or no file was uploaded
}
(I also check error
here because it may be 0
if something went wrong (ie. a file was selected, but there’s no data received). I wouldn’t use name
for this check since that can be overridden). error
with a value of 4
is UPLOAD_ERR_NO_FILE
, so we can check for that too.