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.";
}
Keywords
Related Questions
- In PHP, what are the differences between using the comparison operators == and === when checking for the presence of a substring in a text?
- How can the basename function in PHP be used to extract the file name without the extension?
- How can I properly commit changes to a PHP project in PHPStorm using GIT integration?