Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Graceful degradation for mime type determination
- Loading branch information
Hugh Bragg
committed
Apr 5, 2013
1 parent
3d4ae07
commit e9a2fc6
Showing
4 changed files
with
32 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
// Hugh Bragg | ||
function getMimeType($filename) | ||
{ | ||
$mimetype = false; | ||
if(function_exists('finfo_open')) { | ||
// open with FileInfo | ||
$finfo = finfo_open(FILEINFO_MIME_TYPE); | ||
$mimetype = finfo_file($finfo, $filename); | ||
finfo_close($finfo); | ||
} elseif(function_exists('exif_imagetype')) { | ||
// open with EXIF | ||
$extifType = exif_imagetype($filename); | ||
$mimetype = image_type_to_mime_type($extifType); | ||
} elseif(function_exists('getimagesize')) { | ||
// open with GD | ||
$info = getimagesize($filename); | ||
$mimetype = $info['mime']; | ||
} elseif(function_exists('mime_content_type')) { | ||
// PHP < 5.3 | ||
$mimetype = mime_content_type($filename); | ||
} | ||
return $mimetype; | ||
} |
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