function _imagefield_widget_upload_validate in ImageField 5.2
1 call to _imagefield_widget_upload_validate()
- _imagefield_widget_prepare_form_values in ./imagefield.module
File
- ./imagefield.module, line 873
- Defines an image field type.
imagefield uses content.module to store the fid, and the drupal files
table to store the actual file data.
Code
function _imagefield_widget_upload_validate($node, $field, $items, $file) {
$valid = true;
if (!empty($field['widget']['file_extensions'])) {
$ext = strtolower(array_pop(explode('.', $file['filename'])));
$allowed_extensions = array_unique(explode(' ', strtolower(trim($field['widget']['file_extensions']))));
if (!in_array($ext, $allowed_extensions)) {
form_set_error($field['field_name'], t('Files with the extension %ext are not allowed. Please upload a file with an extension from the following list: %allowed_extensions', array(
'%ext' => $ext,
'%allowed_extensions' => $field['widget']['file_extensions'],
)));
$valid = false;
}
}
if (!empty($field['widget']['max_filesize'])) {
if ($file['filesize'] > $field['widget']['max_filesize'] * 1024) {
form_set_error($field['field_name'], t('The file you uploaded has a filesize greater than the maximum allowed filesize of %sizekb.', array(
'%size' => $field['widget']['max_filesize'],
)));
$valid = false;
}
}
if (strpos($file['filemime'], 'image/') !== 0) {
form_set_error($field['field_name'], t('Mime Type mismatch. Only image files may be upload. You uploaded a file with mime type: %mime', array(
'%mime' => $file['filemime'],
)));
$valid = false;
}
if ($field['multiple'] && !empty($field['widget']['max_number_images'])) {
$count = count($items) + count($_SESSION['imagefield'][$field['field_name']]);
if ($count >= $field['widget']['max_number_images']) {
form_set_error($field['field_name'], t('You are only allowed to upload up to %maximages images.', array(
'%maximages' => $field['widget']['max_number_images'],
)));
$valid = false;
}
}
return $valid;
}