function file_entity_get_upload_validators in File Entity (fieldable files) 7.2
Same name and namespace in other branches
- 7.3 file_entity.pages.inc \file_entity_get_upload_validators()
Retrieves the upload validators for a file.
Parameters
array $options: (optional) An array of options for file validation.
Return value
array An array suitable for passing to file_save_upload() or for a managed_file or upload element's '#upload_validators' property.
3 calls to file_entity_get_upload_validators()
- file_entity_add_upload_step_upload in ./
file_entity.pages.inc - Generate form fields for the first step in the add file wizard.
- file_entity_edit in ./
file_entity.pages.inc - Page callback: Form constructor for the file edit form.
- file_entity_upload_archive_form in ./
file_entity.pages.inc
File
- ./
file_entity.pages.inc, line 1250 - Supports file operations including View, Edit, and Delete.
Code
function file_entity_get_upload_validators(array $options = array()) {
// Set up file upload validators.
$validators = array();
// Validate file extensions. If there are no file extensions in $params and
// there are no Media defaults, there is no file extension validation.
if (!empty($options['file_extensions'])) {
$validators['file_validate_extensions'] = array(
$options['file_extensions'],
);
}
else {
$validators['file_validate_extensions'] = array(
variable_get('file_entity_default_allowed_extensions', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv weba webp webm'),
);
}
// Cap the upload size according to the system or user defined limit.
$max_filesize = parse_size(file_upload_max_size());
$file_entity_max_filesize = parse_size(variable_get('file_entity_max_filesize', ''));
// If the user defined a size limit, use the smaller of the two.
if (!empty($file_entity_max_filesize)) {
$max_filesize = min($max_filesize, $file_entity_max_filesize);
}
if (!empty($options['max_filesize']) && $options['max_filesize'] < $max_filesize) {
$max_filesize = parse_size($options['max_filesize']);
}
// There is always a file size limit due to the PHP server limit.
$validators['file_entity_validate_size_extensions'] = array(
$max_filesize,
);
// Add image validators.
$options += array(
'min_resolution' => 0,
'max_resolution' => 0,
);
if ($options['min_resolution'] || $options['max_resolution']) {
$validators['file_validate_image_resolution'] = array(
$options['max_resolution'],
$options['min_resolution'],
);
}
// Add other custom upload validators from options.
if (!empty($options['upload_validators'])) {
$validators += $options['upload_validators'];
}
return $validators;
}