public static function AmazonS3StreamWrapper::getMimeType in AmazonS3 7
Determine a file's media type.
Uses Drupal's mimetype mappings. Returns 'application/octet-stream' if no match is found.
Return value
string Returns a string representing the file's MIME type
Overrides DrupalStreamWrapperInterface::getMimeType
1 call to AmazonS3StreamWrapper::getMimeType()
- AmazonS3StreamWrapper::stream_flush in ./
AmazonS3StreamWrapper.inc - Support for fflush(). Flush current cached stream data to storage.
File
- ./
AmazonS3StreamWrapper.inc, line 325 - Drupal stream wrapper implementation for Amazon S3
Class
- AmazonS3StreamWrapper
- @file Drupal stream wrapper implementation for Amazon S3
Code
public static function getMimeType($uri, $mapping = NULL) {
// Load the default file map.
if (!isset(self::$mapping)) {
include_once DRUPAL_ROOT . '/includes/file.mimetypes.inc';
self::$mapping = file_mimetype_mapping();
}
$extension = '';
$file_parts = explode('.', 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(self::$mapping['extensions'][$extension])) {
return self::$mapping['mimetypes'][self::$mapping['extensions'][$extension]];
}
}
return 'application/octet-stream';
}