You are here

function photos_upload_form_submit in Album Photos 6.2

Same name and namespace in other branches
  1. 7.3 inc/photos.edit.inc \photos_upload_form_submit()
1 string reference to 'photos_upload_form_submit'
photos_upload_form in inc/photos.edit.inc

File

inc/photos.edit.inc, line 96

Code

function photos_upload_form_submit($form, &$form_state) {
  global $user;
  $limits = _upload_file_limits($user);
  $validators = array(
    'file_validate_is_image' => array(),
    'file_validate_image_resolution' => array(
      $limits['resolution'],
    ),
    'file_validate_size' => array(
      $limits['file_size'],
      $limits['user_size'],
    ),
  );
  $photos_num = variable_get('photos_num', 5);
  for ($i = 0; $i < $photos_num; ++$i) {
    _photos_rename();
    if ($_FILES['files']['name']['images_' . $i]) {
      $value = new stdClass();
      $value->pid = $form_state['values']['pid'];
      $value->nid = $form_state['values']['nid'];
      $value->des = $form_state['values']['des_' . $i];
      $value->title = $form_state['values']['title_' . $i];
      $ext = drupal_substr($_FILES['files']['name']['images_' . $i], -3);
      if ($ext != 'zip' && $ext != 'ZIP') {
        if ($file = file_save_upload('images_' . $i, $validators, photos_check_path())) {
          $msg[] = photos_image_date((object) array_merge((array) $file, (array) $value), 1);
        }
      }
      else {
        if (!variable_get('photos_upzip', 0)) {
          return form_set_error('errer', t('Please Album photos set to open zip upload'));
        }
        $zip = file_destination(file_create_path(photos_check_path() . '/' . trim(basename($_FILES['files']['name']['images_' . $i]))), FILE_EXISTS_RENAME);
        if (move_uploaded_file($_FILES['files']['tmp_name']['images_' . $i], $zip)) {
          if (!($msg = _photos_unzip($zip, $value, $limits))) {
            $msg = t('Failed to upload');
          }
        }
      }
    }
  }
  if (is_array($msg)) {
    return drupal_set_message(t('%count image(s) uploaded successfully.', array(
      '%count' => count($msg),
    )));
  }
  else {
    return drupal_set_message($msg);
  }
}