You are here

function media_file_validate_types in D7 Media 7

Same name and namespace in other branches
  1. 7.4 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

$file: A Drupal file object.

$types: An array of media type names

Return value

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

See also

hook_file_validate()

File

./media.module, line 1111
Media API

Code

function media_file_validate_types(stdClass $file, $types) {
  $errors = array();
  if (!in_array(media_get_type($file), $types)) {
    $errors[] = t('Only the following types of files are allowed to be uploaded: %types-allowed', array(
      '%types-allowed' => implode(', ', $types),
    ));
  }
  return $errors;
}