function nginx_progress_fetch in FileField Nginx Progress 7
Same name and namespace in other branches
- 6 filefield_nginx_progress.module \nginx_progress_fetch()
- 7.2 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_ajax in ./
filefield_nginx_progress.module - Menu callback for nginx upload progress.
File
- ./
filefield_nginx_progress.module, line 106 - 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 = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://';
$base_url = $proto . $domain;
$url = url($base_url . '/progress', array(
'query' => array(
'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;
}