1 file.pages.inc file_get_filetype_candidates(File $file, $selected_files = array())

Get the candidate filetypes for a given file.

Only filetypes for which the user has access to create entities are returned.


File $file: An upload file array from form_state.

Return value

array: An array of file type bundles that support the file's mime type.


core/modules/file/file.pages.inc, line 207
Supports file operations including Manage and Delete.


function file_get_filetype_candidates(File $file, $selected_files = array()) {
  $types = module_invoke_all('file_type', $file);
  backdrop_alter('file_type', $types, $file);

  // If no file types are selected in field instance settings, allow all
  // available types.
  if (!empty($selected_files)) {
    // Limit file type candidates to field allowed types.
    $types = array_intersect($types, $selected_files);

  $candidates = array();
  foreach ($types as $type) {
    $file->type = $type;
    if (file_access('create', $file)) {
      $candidates[$type] = file_type_get_name($file);
  return $candidates;