You are here

function filefield_nginx_progress_ajax in FileField Nginx Progress 7.2

Same name and namespace in other branches
  1. 7 filefield_nginx_progress.module \filefield_nginx_progress_ajax()

Menu callback for nginx upload progress.

Parameters

integer $key: The upload element ID to be used by the nginx progress upload module to identify a particular upload.

Return value

string The response given by the Nginx module in JSON.

1 string reference to 'filefield_nginx_progress_ajax'
filefield_nginx_progress_menu in ./filefield_nginx_progress.module
Implements hook_menu().

File

./filefield_nginx_progress.module, line 39
filefield_nginx_progress.module @author Ben Osman <dev@smoothify.com> António P. P. Almeida <appa@perusio.net> @date Sun Oct 21 14:31:03 2012

Code

function filefield_nginx_progress_ajax($key) {
  $progress = array(
    'message' => t('Starting upload...'),
    'percentage' => -1,
  );

  // Get the status.
  $status = nginx_progress_fetch($key);
  if ($status['state'] == 'uploading') {

    // We set a message only when the upload is in progress.
    $progress['message'] = t('Uploading... (@current of @total)', array(
      '@current' => format_size($status['received']),
      '@total' => format_size($status['size']),
    ));
    $progress['percentage'] = round(100 * $status['received'] / $status['size']);
  }

  // Output as JSON so that the JS progress bar can use it.
  drupal_json_output($progress);
}