You are here

function user_badges_images_form_submit in User Badges 5

Same name and namespace in other branches
  1. 6.2 user_badges.admin.inc \user_badges_images_form_submit()
  2. 6 user_badges.admin.inc \user_badges_images_form_submit()
  3. 7 user_badges.admin.inc \user_badges_images_form_submit()
  4. 7.2 user_badges.admin.inc \user_badges_images_form_submit()
  5. 7.3 user_badges.admin.inc \user_badges_images_form_submit()

File

./user_badges.module, line 451
@brief User Badges module file

Code

function user_badges_images_form_submit($form_id, $form_values) {
  $op = $form_values['op'];

  // Save uploaded files
  if ($op == t('Upload')) {
    $dir = file_create_path('badges');
    $is_writable = file_check_directory($dir, 1);
    if ($is_writable) {
      if ($source = file_check_upload('upload')) {

        // Security measure to prevent exploit of file.php.png
        $source->filename = upload_munge_filename($source->filename);
        if ($file = file_save_upload($source, $dir)) {
          if (image_get_info($file->filepath)) {
            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 {
    if ($op == t('Delete')) {
      foreach ($form_values['images'] as $path => $is_removed) {
        if ($is_removed) {
          $to_delete[] = $path;
        }
      }
      if (is_array($to_delete)) {
        user_badges_image_delete($to_delete);
      }
    }
  }
}