Same name and namespace in other branches
  1. 4.7.x modules/user.module \user_validate_picture()
  2. 5.x modules/user/user.module \user_validate_picture()
  3. 6.x modules/user/user.module \user_validate_picture()
  4. 7.x modules/user/user.module \user_validate_picture()
1 call to user_validate_picture()
user_edit_validate in modules/user.module

File

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

Code

function user_validate_picture($file, &$edit, $user) {

  // Initialize the picture:
  $edit['picture'] = $user->picture;

  // Check that uploaded file is an image, with a maximum file size
  // and maximum height/width.
  $info = image_get_info($file->filepath);
  list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85'));
  if (!$info || !$info['extension']) {
    form_set_error('picture', t('The uploaded file was not an image.'));
  }
  else {
    if (image_get_toolkit()) {
      image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
    }
    else {
      if (filesize($file->filepath) > variable_get('user_picture_file_size', '30') * 1000) {
        form_set_error('picture', t('The uploaded image is too large; the maximum file size is %size kB.', array(
          '%size' => variable_get('user_picture_file_size', '30'),
        )));
      }
      else {
        if ($info['width'] > $maxwidth || $info['height'] > $maxheight) {
          form_set_error('picture', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array(
            '%dimensions' => variable_get('user_picture_dimensions', '85x85'),
          )));
        }
      }
    }
  }
  if (!form_get_errors()) {
    if ($file = file_save_upload('picture', variable_get('user_picture_path', 'pictures') . '/picture-' . $user->uid . '.' . $info['extension'], 1)) {
      $edit['picture'] = $file->filepath;
    }
    else {
      form_set_error('picture', t("Failed to upload the picture image; the %directory directory doesn't exist.", array(
        '%directory' => '<em>' . variable_get('user_picture_path', 'pictures') . '</em>',
      )));
    }
  }
}