Set header with the correct Mime-Type of content from an URL address
Posted: 19 Aug 2015, 15:41
Hello
I have this script that gets the content from an URL address and outputs it to the browser.
I need to add the mime-type into the header('Content-Type: ...') to can properly output that resource. But the resource type is variable, it can be a PDF file, a DOC, or an image (JPG, PNG, ...).
So, how can I get the correct Mime Type of a content from an Url address?
I have this script that gets the content from an URL address and outputs it to the browser.
Code: Select all
$url = 'the_url_address';
$content = file_get_contents($url); //gets the content
// here i need to set the header with the correct Content-Type
header('Content-Type: ...');
echo $cnt;
exit;
So, how can I get the correct Mime Type of a content from an Url address?