function designkit_upload_validate in DesignKit 7
Same name and namespace in other branches
- 6 designkit.admin.inc \designkit_upload_validate()
Element validator for image upload. Handles file creation and value setting tasks all at once.
1 string reference to 'designkit_upload_validate'
- _designkit_form_alter in ./
designkit.admin.inc - Implementation of hook_form_alter() for spaces_features_form, system_theme_settings.
File
- ./
designkit.admin.inc, line 178
Code
function designkit_upload_validate($element, &$form_state) {
$name = end($element['#parents']);
// Clean out upload values.
unset($form_state['values'][$name]);
// Save uploaded file.
$validators = array(
'file_validate_is_image' => array(),
'file_validate_image_resolution' => array(
'3000x3000',
),
'file_validate_size' => array(
1000 * 1024,
),
);
$file = file_save_upload($name, $validators, 'public://');
$error = $file ? file_validate_is_image($file) : FALSE;
// Save the new file & settings.
if ($file && !$error) {
$file->status |= FILE_STATUS_PERMANENT;
$file = file_save($file);
image_path_flush($file->uri);
$form_state['values']['designkit_image'][$name] = $file->fid;
}
else {
if ($error) {
form_set_error($name, $error);
}
if ($file) {
file_delete($file->uri);
db_delete('file_managed')
->condition('fid', $file->fid)
->execute();
}
$form_state['values']['designkit_image'][$name] = 0;
}
}