function upload_element_js in Upload element 6
Handles the AHAH upload request.
Parameters
string $name The elements name.:
1 string reference to 'upload_element_js'
- upload_element_menu in ./
upload_element.module - Implementation of hook_menu().
File
- ./
upload_element.pages.inc, line 123 - Handles image previews from both temperary and perminant file directories.
Code
function upload_element_js($form_build_id, $form_id, $name) {
$GLOBALS['devel_shutdown'] = FALSE;
$form_state = array(
'submitted' => FALSE,
);
// The only way to detect if the max post size was exceeded is to check the $_POST
// The $for_build_id is potentially stale (from changing form_build_id)
// but is the only reference we have if the $_POST has been dropped by
// PHP by exceeding the MAX_FORM_SIZE limit.
// TODO: Find out what is happening to the AHAH during rebuild.
if (empty($_POST)) {
form_set_error($name, t("The file %file could not be saved, because it exceeds this form's size limit %size for file uploads.", array(
'%file' => $_FILES['files']['name'][$name],
'%size' => format_size(file_upload_max_size()),
)), 'error');
}
else {
$form_build_id = $_POST['form_build_id'];
}
if ($form_build_id && ($form = form_get_cache($form_build_id, $form_state))) {
$form += array(
'#post' => $_POST,
);
if ($element = locate_upload_element($form, $name, array(
'#is_ahah' => TRUE,
))) {
$form = form_builder($form_id, $form, $form_state);
$element = locate_upload_element($form, $name);
$element['#messages'] = theme('status_messages');
$output = drupal_render($element);
print drupal_to_js(array(
'data' => $output,
));
exit;
}
}
else {
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;
}