Stan
Stan

Reputation: 26501

How to check if file is selected

I have file $fileImage = $_FILES['fileCatImg'];, everything works when I try to upload it, but how do I check if file is selected first? if (isset($fileImage)) and if (empty($fileImage)) are not working. One of them always returns true value, but other always returns false value.

Upvotes: 3

Views: 3315

Answers (2)

Oswald
Oswald

Reputation: 31637

No file was uploaded when $_FILES['fileCatImg']['error'] == UPLOAD_ERR_NO_FILE, but that is only useful to determine an appropriate error message. See Error Messages Explained for other values that $_FILES['fileCatImg']['error'] might assume when something goes wrong during file uploads.

Upvotes: 1

smottt
smottt

Reputation: 3330

Check file size:

if($_FILES['fileCatImg']['size'] > 0) { ... }

Upvotes: 4

Related Questions