How to test if a user has SELECTED a file to upload?

You can check this with:

if (empty($_FILES['logo']['name'])) {
    // No file was selected for upload, your (re)action goes here
}

Or you can use a javascript construction that only enables the upload/submit button whenever the upload field has a value other then an empty string (“”) to avoid submission of the form with no upload at all.

Leave a Comment