public static function S3fsStreamWrapper::getMimeType in S3 File System 7
Same name and namespace in other branches
- 7.3 S3fsStreamWrapper.inc \S3fsStreamWrapper::getMimeType()
- 7.2 S3fsStreamWrapper.inc \S3fsStreamWrapper::getMimeType()
Static function to determine a file's media type.
Uses Drupal's mimetype mapping, unless a different mapping is specified.
Return value
string Returns a string representing the file's MIME type, or 'application/octet-stream' if no type cna be determined.
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 233 - Drupal stream wrapper implementation for S3 File System.
Class
- S3fsStreamWrapper
- The stream wrapper class.
Code
public static function getMimeType($uri, $mapping = NULL) {
self::_debug("getMimeType({$uri}, {$mapping}) called.");
// 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('.', 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 types matches, so return the default.
return 'application/octet-stream';
}