function upload_js in Drupal 5
Same name and namespace in other branches
- 4 modules/upload.module \upload_js()
- 6 modules/upload/upload.module \upload_js()
Menu-callback for JavaScript-based uploads.
1 string reference to 'upload_js'
- upload_menu in modules/
upload/ upload.module - Implementation of hook_menu().
File
- modules/
upload/ upload.module, line 880 - File-handling and attaching files to nodes.
Code
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;
}