user_validate_picture
Definition
user_validate_picture(&$form, &$form_state)
modules/user/user.module, line 400
Code
<?php
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_unmanaged_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 = file_create_path(variable_get('user_picture_path', 'pictures') . '/picture-' . $form['#uid'] . '.' . $info['extension']);
if ($filepath = file_unmanaged_copy($file->filepath, $destination, FILE_EXISTS_REPLACE)) {
$form_state['values']['picture'] = $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'))));
}
}
}
?> 