public static function S3fsStreamWrapper::getMimeType in S3 File System 7.3
Same name and namespace in other branches
- 7 S3fsStreamWrapper.inc \S3fsStreamWrapper::getMimeType()
- 7.2 S3fsStreamWrapper.inc \S3fsStreamWrapper::getMimeType()
Returns the MIME type of the resource.
Parameters
$uri: The URI, path, or filename.
$mapping: An optional map of extensions to their mimetypes, in the form:
- 'mimetypes': a list of mimetypes, keyed by an identifier,
- 'extensions': the mapping itself, an associative array in which the key is the extension and the value is the mimetype identifier.
Return value
Returns a string containing the MIME type of the resource.
Overrides DrupalStreamWrapperInterface::getMimeType
1 call to S3fsStreamWrapper::getMimeType()
- S3fsStreamWrapper::stream_flush in ./
S3fsStreamWrapper.inc - Support for fflush(). Flush current cached stream data to a file in S3.
File
- ./
S3fsStreamWrapper.inc, line 262 - Drupal stream wrapper implementation for S3 File System.
Class
- S3fsStreamWrapper
- The stream wrapper class.
Code
public static function getMimeType($uri, $mapping = NULL) {
// Load the default mime type map.
if (!isset(self::$mimeTypeMapping)) {
include_once DRUPAL_ROOT . '/includes/file.mimetypes.inc';
self::$mimeTypeMapping = file_mimetype_mapping();
}
// If a mapping wasn't specified, use the default map.
if ($mapping == NULL) {
$mapping = self::$mimeTypeMapping;
}
$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
// - 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]];
}
}
// No mime type matches, so return the default.
return 'application/octet-stream';
}