You are here

function avatar_selection_images_form_submit in Avatar Selection 5

File

./avatar_selection.module, line 595

Code

function avatar_selection_images_form_submit($form_id, $form_values) {
  $op = $form_values['op'];
  if ($op == t('Upload')) {

    // Save uploaded files
    $dir = file_create_path('avatar_selection');
    $is_writable = file_check_directory($dir, 1);
    if ($is_writable) {
      if ($source = file_check_upload('picture_upload')) {
        if ($file = file_save_upload($source, $dir)) {
          if (image_get_info($file->filepath)) {
            $access = implode(', ', array_keys(array_filter($form_values['access'])));
            if (module_exists("og")) {
              $og = implode(', ', array_keys(array_filter($form_values['og_access'])));
            }
            _avatar_selection_save_avatar_info($file->filepath, $access, $og);
            drupal_set_message(t('New image saved.'));
          }
          else {
            file_delete($file->filepath);
            drupal_set_message('Uploaded file does not appear to be a valid image file. Please try again.');
          }
        }
      }
    }
    else {
      form_set_error('picture_upload', t('Directory not writable: !dir', array(
        '!dir' => $dir,
      )));
    }
  }
}