You are here

function filefield_nginx_progress_process in FileField Nginx Progress 6

A #process callback to extend the filefield_widget element type.

To get the field working with nginx upload progress, we need to enable the progress bar and modify the ahah paths to work with the nginx redirection.

1 string reference to 'filefield_nginx_progress_process'
filefield_nginx_progress_elements in ./filefield_nginx_progress.module
Implementation of hook_elements().

File

./filefield_nginx_progress.module, line 69
Adds upload progress functionality to FileFields on the nginx webserver.

Code

function filefield_nginx_progress_process($element, $edit, &$form_state, $form) {

  // Generate upload progress key
  $upload_progress_key = md5(mt_rand());

  // Nginx really wants us to send a get value, but form_expand_ahah doesn't
  // allow query strings in paths. The work around is to add the progress id
  // into the path and to rewrite at the nginx level to the required url.
  $element['filefield_upload']['#ahah']['path'] .= '/x-progress-id:' . $upload_progress_key;

  // Add the upload key to the form, in a manner compatible with the existing
  // javascript
  $element['UPLOAD_IDENTIFIER'] = array(
    '#type' => 'hidden',
    '#value' => $upload_progress_key,
    '#attributes' => array(
      'class' => 'filefield-progress',
    ),
  );

  // Unset this as a precaution in the unlikely event that apc upload progress
  // is enabled in php.ini
  unset($element['APC_UPLOAD_PROGRESS']);

  // Enable the progress bar
  $element['filefield_upload']['#ahah']['progress']['type'] = 'bar';

  // Modify the upload progress callback to use our own menu callback.
  $element['filefield_upload']['#ahah']['progress']['path'] = 'filefield_nginx_progress/' . $upload_progress_key;
  return $element;
}