function user_validate_picture in Drupal 6
Same name and namespace in other branches
- 4 modules/user.module \user_validate_picture()
- 5 modules/user/user.module \user_validate_picture()
- 7 modules/user/user.module \user_validate_picture()
1 string reference to 'user_validate_picture'
- user_edit_form in modules/
user/ user.module
File
- modules/
user/ user.module, line 435 - Enables the user registration and login system.
Code
function user_validate_picture(&$form, &$form_state) {
// If required, validate the uploaded picture.
$validators = array(
'file_validate_is_image' => array(),
'file_validate_image_resolution' => array(
variable_get('user_picture_dimensions', '85x85'),
),
'file_validate_size' => array(
variable_get('user_picture_file_size', '30') * 1024,
),
);
if ($file = file_save_upload('picture_upload', $validators)) {
// Remove the old picture.
if (isset($form_state['values']['_account']->picture) && file_exists($form_state['values']['_account']->picture)) {
file_delete($form_state['values']['_account']->picture);
}
// The image was saved using file_save_upload() and was added to the
// files table as a temporary file. We'll make a copy and let the garbage
// collector delete the original upload.
$info = image_get_info($file->filepath);
$destination = variable_get('user_picture_path', 'pictures') . '/picture-' . $form['#uid'] . '.' . $info['extension'];
if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
$form_state['values']['picture'] = $file->filepath;
}
else {
form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.", array(
'%directory' => variable_get('user_picture_path', 'pictures'),
)));
}
}
}