upload_js

Versions
4.7 – 7
upload_js()

Menu-callback for JavaScript-based uploads.

Code

modules/upload/upload.module, line 879

<?php
function upload_js() {
  if (isset($_POST['vid']) && is_numeric($_POST['vid'])) {
    // Load the node and check the user is allowed to post attachments to it.
    $node = node_load(array('vid' => $_POST['vid']));
    if (!$node || !node_access('update', $node) || !variable_get('upload_'. $node->type, TRUE)) {
      // Setting this error will cause the form to fail validation.
      form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.'));
      $output = theme('status_messages');
      print drupal_to_js(array('status' => TRUE, 'data' => $output));
      exit();
    }
  }
  else {
    // This is a new node.
    $node = new stdClass();
  }

  // Load existing node files.
  $node->files = upload_load($node);

  // Handle new uploads, and merge tmp files into node-files.
  _upload_prepare($node);
  _upload_validate($node);

  $form = _upload_form($node);
  foreach (module_implements('form_alter') as $module) {
    $function = $module .'_form_alter';
    $function('upload_js', $form);
  }
  $form = form_builder('upload_js', $form);
  $output = theme('status_messages') . drupal_render($form);
  // We send the updated file attachments form.
  print drupal_to_js(array('status' => TRUE, 'data' => $output));
  exit;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.