You are here

function _privatemsg_attachments_upload_submit in Privatemsg 6.2

1 call to _privatemsg_attachments_upload_submit()
privatemsg_attachments_upload_js in privatemsg_attachments/privatemsg_attachments.module
Menu callback for JavaScript-based uploads.
1 string reference to '_privatemsg_attachments_upload_submit'
privatemsg_attachments_form_privatemsg_new_alter in privatemsg_attachments/privatemsg_attachments.module
Implements hook_form_FORM_ID_alter().

File

privatemsg_attachments/privatemsg_attachments.module, line 238
Allows users to add attachments to messages

Code

function _privatemsg_attachments_upload_submit(&$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.
  $dir = variable_get('privatemsg_attachments_upload_dir', '');
  if (!empty($dir) && $dir[0] !== '/') {
    $dir = '/' . $dir;
  }
  if (user_access('upload private message attachments') && ($file = file_save_upload('upload', $validators, file_directory_path() . $dir))) {
    $file->list = variable_get('upload_list_default', 1);
    $file->description = $file->filename;
    $file->weight = 0;
    $file->new = TRUE;
    $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');
  }
}