Created
August 6, 2014 16:42
-
-
Save primitive-type/1eb69794b6e25e23e091 to your computer and use it in GitHub Desktop.
Get MIME types for CDN hosted files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fileUrl = 'http://t2.gstatic.com/images?q=tbn:ANd9GcS8ntYWjylXybJ4WIr5WvFJiknlXdS8jkhwpaRXqhCY3w2vFyuR-Q'; | |
// Get the file's MIME type | |
// This method is used because many file URLs hosted on CDNs do not contain file extensions | |
$finfo = new finfo(FILEINFO_MIME_TYPE); | |
$mediaType = $finfo->buffer(file_get_contents($fileUrl)); | |
// Is this an image, audio, text, video, etc.? | |
$type = dirname($mediaType); | |
// Probably your best guess at the file extension when it's not contained in the URL | |
$subtype = basename($mediaType); | |
echo $mediaType; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment