1 user.module user_validate_picture(&$form, &$form_state)

Validates an image uploaded by a user.

See also

user_account_form()

File

core/modules/user/user.module, line 407
Enables the user registration and login system.

Code

function user_validate_picture(&$form, &$form_state) {
  $site_config = config('system.core');
  // If required, validate the uploaded picture.
  $validators = array(
    'file_validate_is_image' => array(),
    'file_validate_image_orientation' => array(TRUE),
    'file_validate_image_resolution' => array($site_config->get('user_picture_dimensions')),
    'file_validate_size' => array((int) $site_config->get('user_picture_file_size') * 1024),
  );

  // Save the file as a temporary file.
  $file = file_save_upload('picture_upload', $validators);
  if ($file === FALSE) {
    form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.", array('%directory' => $site_config->get('user_picture_path'))));
  }
  elseif ($file !== NULL) {
    $form_state['values']['picture_upload'] = $file;
  }
}