You are here

public function MimetypeService::extensionsToMimetypes in Search File Attachments 8

Convert file extensions to the corresponding mimetype.

Parameters

string $filetypes: A comma-separated string of file extensions.

Return value

array The array of corresponsing mimetypes.

File

src/MimetypeService.php, line 137

Class

MimetypeService
Service that handles the mimetypes of file extensions.

Namespace

Drupal\search_file_attachments

Code

public function extensionsToMimetypes($filetypes) {
  $filetypes = preg_replace('/[^a-zA-z0-9\\/\\-,]/', '', $filetypes);
  $filetypes = explode(',', $filetypes);
  $mimetypes = array();
  if (!empty($filetypes)) {
    foreach ($filetypes as $type) {
      if ($mt = $this
        ->extensionToMimetype($type)) {
        $mimetypes[] = $mt;
      }
    }
  }
  return $mimetypes;
}