DrupalLocalStreamWrapper::getMimeType
static function DrupalLocalStreamWrapper::getMimeType
static DrupalLocalStreamWrapper::getMimeType($uri, $mapping = NULL)
Base implementation of getMimeType().
Overrides DrupalStreamWrapperInterface::getMimeType
File
- includes/stream_wrappers.inc, line 311
- Drupal stream wrapper interface.
Class
- DrupalLocalStreamWrapper
- Drupal stream wrapper base class for local files.
Code
static function getMimeType($uri, $mapping = NULL) { 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('.', drupal_basename($uri)); // 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 = strtolower($additional_part . ($extension ? '.' . $extension : '')); if (isset($mapping['extensions'][$extension])) { return $mapping['mimetypes'][$mapping['extensions'][$extension]]; } } return 'application/octet-stream'; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!stream_wrappers.inc/function/DrupalLocalStreamWrapper::getMimeType/7.x