You are here

function dynamic_background_user_upload_form_submit in Dynamic Background 7.2

Submission callback for user uploaded image, which stores the image(s) uploaded and stores the last uploaded image in the $form_state values info array. So extension automatically can activate the last uploaded image.

1 string reference to 'dynamic_background_user_upload_form_submit'
dynamic_background_user_upload_form in ./dynamic_background.module
Hepler function that build an upload form, which can be used by sub-modules to allow uploading of files.

File

./dynamic_background.module, line 738
This module enables administrators to upload images used as background on the site. The selected background image link is exposed as either $background in the page.tpl file or as /background.css.

Code

function dynamic_background_user_upload_form_submit($form, &$form_state) {

  // Run through the uploaded files and save them.
  if (!empty($_FILES)) {
    foreach ($_FILES['files']['name'] as $file_field => $val) {
      if (!empty($val) && strpos($file_field, 'dynamic_background') === 0) {
        try {

          // Get information about the extension uploading the image.
          $info = $form_state['values']['dynamic_background']['dynamic_background_info'];

          // Save the image.
          $fid = dynamic_background_save_image($file_field, $info['type'], $info['data']);

          // Save fid for the last upload image, which can be used to set it
          // active else where.
          $form_state['values']['dynamic_background']['dynamic_background_info']['active'] = $fid;
        } catch (Exception $e) {
          form_set_error($file_field, $e
            ->getMessage());
        }
      }
    }
  }

  // Check for image deletion and if image have been selected.
  foreach ($form_state['values']['dynamic_background']['dynamic_background_picture_upload'] as $field => $data) {
    if (isset($data['picture_delete']) && $data['picture_delete']) {
      try {
        dynamic_background_delete_image($data['fid']);
      } catch (Exception $e) {
        form_set_error($field, $e
          ->getMessage());
      }
    }

    // Test if an image have been selected among the upload files.
    if (isset($data['picture_use']) && $data['picture_use']) {
      $form_state['values']['dynamic_background']['dynamic_background_info']['active'] = $data['fid'];
    }
  }
}