function file_field_widget_upload_validators

Retrieves the upload validators for a file field.

Parameters

$field: A field array.

Return value

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

1 call to file_field_widget_upload_validators()
file_field_widget_form in modules/file/file.field.inc
Implements hook_field_widget_form().

File

modules/file/file.field.inc, line 549

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.