You are here

function nginx_progress_fetch in FileField Nginx Progress 6

Same name and namespace in other branches
  1. 7.2 filefield_nginx_progress.module \nginx_progress_fetch()
  2. 7 filefield_nginx_progress.module \nginx_progress_fetch()

Fetch the upload progress from nginx using the X-Progress-ID parameter

Since the javascript returned by the progress tracking in nginx is not compatible with the ahah progress bar, we need to get drupal to issue an http request and then parse the response.

1 call to nginx_progress_fetch()
filefield_nginx_progress in ./filefield_nginx_progress.module
Menu callback for nginx upload progress.

File

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

Code

function nginx_progress_fetch($key) {

  // Find root url of server
  $domain = $_SERVER['HTTP_HOST'];
  $proto = $_SERVER['HTTPS'] ? 'https://' : 'http://';
  $base_url = $proto . $domain;
  $url = url($base_url . '/progress', array(
    'query' => 'X-Progress-ID=' . $key,
    'absolute' => TRUE,
    'external' => TRUE,
  ));
  $response = drupal_http_request($url);
  $status = array();

  // strip the extraneous parts out leaving a comma delimited list.
  if (preg_match("/\\{(.*)\\}/", $response->data, $matches)) {
    $items = explode(',', $matches[1]);
    foreach ($items as $item) {
      $array = explode(':', $item);

      // strip quotes and spaces from key & value pair
      $key = trim($array[0], "' ");
      $value = trim($array[1], "' ");
      $status[$key] = $value;
    }
  }
  return $status;
}