1 file.module file_match_mimetypes($needle, $haystack)

Checks if pattern(s) match mimetype(s).

File

core/modules/file/file.module, line 2026
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

function file_match_mimetypes($needle, $haystack) {
  $needle = is_array($needle) ? $needle : array($needle);
  $haystack = is_array($haystack) ? $haystack : array($haystack);

  foreach ($haystack as $mimetype) {
    foreach ($needle as $search) {
      if (is_null($search) || is_null($mimetype)) {
        continue;
      }
      if (fnmatch($search, $mimetype) || fnmatch($mimetype, $search)) {
        return TRUE;
      }
    }
  }

  return FALSE;
}