Check if file is image

<?php
$file_path = 'example.jpg';

$image_info = getimagesize($file_path);

if ($image_info !== false) {
    if (strpos($image_info['mime'], 'image/') === 0) {
        echo "The file is an image.";
    } else {
        echo "The file is not an image.";
    }
} else {
    echo "The file is not accessible or is not an image.";
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *