1 file.module file_type_get_valid_extensions($type)

Returns an array of valid file extensions.

File

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

Code

function file_type_get_valid_extensions($type) {
  include_once BACKDROP_ROOT . '/core/includes/file.mimetypes.inc';
  $mapping = file_mimetype_mapping();

  $type_extensions = array();
  $type_ext_keys = array();
  if (!empty($type->mimetypes)) {
    foreach ($mapping['mimetypes'] as $ext_key => $mimetype) {
      if (file_match_mimetypes($mimetype, $type->mimetypes)) {
        $type_ext_keys[] = $ext_key;
      }
    }

    if ($type_ext_keys) {
      $type_extensions = array_intersect($mapping['extensions'], $type_ext_keys);
      $type_extensions = array_keys($type_extensions);
    }
  }

  return $type_extensions;
}