function _cdn_basic_farfuture_get_mimetype in CDN 7.2
Same name and namespace in other branches
- 6.2 cdn.basic.farfuture.inc \_cdn_basic_farfuture_get_mimetype()
Determine an Internet Media Type, or MIME type from a filename. Borrowed from Drupal 7.
Parameters
$path: A string containing the file path.
Return value
The internet media type registered for the extension or application/octet-stream for unknown extensions.
1 call to _cdn_basic_farfuture_get_mimetype()
File
- ./
cdn.basic.farfuture.inc, line 419 - Far Future expiration setting for basic mode.
Code
function _cdn_basic_farfuture_get_mimetype($path) {
static $mapping;
if (!isset($mapping)) {
// The default file map, defined in file.mimetypes.inc is quite big.
// We only load it when necessary.
include_once DRUPAL_ROOT . '/includes/file.mimetypes.inc';
$mapping = file_mimetype_mapping();
}
$extension = '';
$file_parts = explode('.', basename($path));
// Remove the first part: a full filename should not match an extension.
array_shift($file_parts);
// Iterate over the file parts, trying to find a match.
// For my.awesome.image.jpeg, we try:
// - jpeg
// - image.jpeg, and
// - awesome.image.jpeg
while ($additional_part = array_pop($file_parts)) {
$extension = drupal_strtolower($additional_part . ($extension ? '.' . $extension : ''));
if (isset($mapping['extensions'][$extension])) {
return $mapping['mimetypes'][$mapping['extensions'][$extension]];
}
}
return 'application/octet-stream';
}