php - check if file in $_FILES is an image

voted: 1

Checking if file in $_FILES is an image.


if ($_FILES['file']['error'] !== UPLOAD_ERR_OK) {
    //error occured during upload, abort script or do something with error
} else {
    if (isset($_FILES['file']['name']) && !empty(getimagesize($_FILES['file']['tmp_name']))) {
        //file is image, proceed with save or do something with file
    } else {
        //file is not image
working url: not entered
version: not entered
Leave a Comment:
Characters left:
No comments yet.