1 file.field.inc file_field_widget_upload_validators($field, $instance)

Retrieves the upload validators for a file field.


$field: A field array.

Return value

An array suitable for passing to file_save_upload() or the file field: element's '#upload_validators' property.


core/modules/file/file.field.inc, line 728
Field module functionality for the File module.


function file_field_widget_upload_validators($field, $instance) {
  // Cap the upload size according to the PHP limit.
  $max_filesize = parse_size(file_upload_max_size());
  if (!empty($instance['settings']['max_filesize']) && parse_size($instance['settings']['max_filesize']) < $max_filesize) {
    $max_filesize = parse_size($instance['settings']['max_filesize']);

  $validators = array();

  // There is always a file size limit due to the PHP server limit.
  $validators['file_validate_size'] = array($max_filesize);

  // Add the extension check if necessary.
  if (!empty($instance['settings']['file_extensions'])) {
    $validators['file_validate_extensions'] = array($instance['settings']['file_extensions']);

  return $validators;