How can you determine if a file is an image or not in PHP?

To determine if a file is an image or not in PHP, you can use the getimagesize() function. This function returns an array with information about the image, including its dimensions and MIME type. By checking the MIME type returned by getimagesize(), you can determine if the file is an image or not.

$file_path = 'path/to/your/file.jpg';

$image_info = getimagesize($file_path);

if($image_info !== false) {
    echo 'This is an image file.';
} else {
    echo 'This is not an image file.';
}