You are here

function media_file_validate_types in D7 Media 7.4

Same name and namespace in other branches
  1. 7 media.module \media_file_validate_types()
  2. 7.2 media.module \media_file_validate_types()
  3. 7.3 media.module \media_file_validate_types()

Check that the media is one of the selected types.

Parameters

object $file: A Drupal file object.

array $types: An array of media type names

Return value

array If the file type is not allowed, it will contain an error message.

See also

hook_file_validate()

File

./media.module, line 1153
Media API

Code

function media_file_validate_types($file, $types) {
  $errors = array();
  if (!function_exists('file_entity_get_filetype_candidates')) {
    module_load_include('inc', 'file_entity', 'file_entity.pages');
  }
  $file_candidates = array_keys(file_entity_get_filetype_candidates($file));
  if (!array_intersect($file_candidates, $types)) {
    $errors[] = t('Only the following types of files are allowed to be uploaded: %types-allowed', array(
      '%types-allowed' => implode(', ', $types),
    ));
  }
  return $errors;
}