If you upload a file using HTTP, do not guess (also called auto-detection) the MIME type. Even if you uploaded the file using file_get_contents , you can still access the HTTP headers.
Use $http_response_header to get the headers of the last call to file_get_contents (or any call from http:// wrapper ).
$contents = file_get_contents("https://www.example.com/image.jpg"); $pattern = "/^content-type\s*:\s*(.*)$/i"; if (($header = preg_grep($pattern, $http_response_header)) && (preg_match($pattern, array_shift(array_values($header)), $match) !== false)) { $content_type = $match[1]; echo "Content-Type is '$content_type'\n"; }
Martin Prikryl
source share