You are here

function node_gallery_upload_images in Node Gallery 6

Same name and namespace in other branches
  1. 6.2 node_gallery.pages.inc \node_gallery_upload_images()
1 call to node_gallery_upload_images()
node_gallery_upload_js in ./node_gallery.pages.inc

File

./node_gallery.pages.inc, line 143
Node gallery pages.

Code

function node_gallery_upload_images(&$form, &$form_state) {
  global $user;
  $limits = _upload_file_limits($user);
  $validators = array(
    'file_validate_extensions' => array(
      $limits['extensions'],
    ),
    'file_validate_image_resolution' => array(
      $limits['resolution'],
    ),
    'file_validate_size' => array(
      $limits['file_size'],
      $limits['user_size'],
    ),
  );

  // Save new file uploads.
  if ($user->uid != 1 || user_access('upload files')) {
    $directory = node_gallery_check_directory($form['#node']);
    foreach ($_FILES['files']['name'] as $id => $name) {
      if (!empty($name)) {
        $file = file_save_upload($id, $validators, $directory);
        if (!empty($file)) {
          $file->description = $file->filename;
          $file->weight = 0;
          $file->gid = $form['#node']->nid;
          $form['#node']->images[$file->fid] = $file;
          $form_state['values']['files'][$file->fid] = (array) $file;
        }
      }
    }
  }

  // Order the form according to the set file weight values.
  if (!empty($form_state['values']['files'])) {
    $microweight = 0.001;
    foreach ($form_state['values']['files'] as $fid => $file) {
      if (is_numeric($fid)) {
        $form_state['values']['files'][$fid]['#weight'] = $file['weight'] + $microweight;
        $microweight += 0.001;
      }
    }
    uasort($form_state['values']['files'], 'element_sort');
  }
}