You are here

function _cdn_basic_farfuture_get_mimetype in CDN 6.2

Same name and namespace in other branches
  1. 7.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()
cdn_basic_farfuture_download in ./cdn.basic.farfuture.inc

File

./cdn.basic.farfuture.inc, line 404
Far Future expiration setting for basic mode.

Code

function _cdn_basic_farfuture_get_mimetype($path) {
  cdn_load_include('mimetypes');
  $mapping = cdn_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';
}