How can one determine the file type of an external image without downloading it to the server in PHP?

To determine the file type of an external image without downloading it to the server in PHP, you can use the get_headers() function to retrieve the headers of the image URL and then check the "Content-Type" header to determine the file type.

$image_url = 'https://example.com/image.jpg';
$headers = get_headers($image_url, 1);

if(isset($headers['Content-Type'])) {
    $file_type = $headers['Content-Type'];
    echo "File type: " . $file_type;
} else {
    echo "Unable to determine file type.";
}