There's barely a mention on this page but the $http_response_header will be populated with the HTTP headers if your file was a link. For example if you're expecting an image you can do this:
<?php
$data = file_get_contents('https://example.net/some-link');
$mimetype = null;
foreach ($http_response_header as $v) {
if (preg_match('/^content\-type:\s*(image\/[^;\s\n\r]+)/i', $v, $m)) {
$mimetype = $m[1];
}
}
if (!$mimetype) {
// not an image
}