filemime.module in File MIME 8
Same filename and directory in other branches
Enables site admins to configure the MIME type mapping for uploaded files.
File
filemime.moduleView source
<?php
/**
* @file
* Enables site admins to configure the MIME type mapping for uploaded files.
*/
/**
* Alter the MIME type mapping based on the mime.types file and/or string.
*/
function filemime_file_mimetype_mapping_alter(&$mapping) {
// Build an array of MIME types from the configured file and string.
$file = \Drupal::config('filemime.settings')
->get('file');
$mimetypes = array_merge(is_readable($file) ? file($file) : [], explode("\n", \Drupal::config('filemime.settings')
->get('types')));
// Split each MIME type into tokens by whitespace.
foreach ($mimetypes as $mimetype) {
$tokens = preg_split('/[\\s]+/', $mimetype, -1, PREG_SPLIT_NO_EMPTY);
foreach ($tokens as $index => $token) {
// If this token starts with #, consider it a comment and break to the
// next MIME type.
if (substr($token, 0, 1) == '#') {
break;
}
// If this is not the first token, it must be an extension. Add it to the
// extensions array.
if ($index) {
$mapping['extensions'][$token] = $tokens[0];
}
elseif (isset($tokens[1])) {
$mapping['mimetypes'][$token] = $token;
}
}
}
}
Functions
Name | Description |
---|---|
filemime_file_mimetype_mapping_alter | Alter the MIME type mapping based on the mime.types file and/or string. |