function FileWidgetAjaxController::progress

Same name in other branches
  1. 9 core/modules/file/src/Controller/FileWidgetAjaxController.php \Drupal\file\Controller\FileWidgetAjaxController::progress()
  2. 8.9.x core/modules/file/src/Controller/FileWidgetAjaxController.php \Drupal\file\Controller\FileWidgetAjaxController::progress()
  3. 10 core/modules/file/src/Controller/FileWidgetAjaxController.php \Drupal\file\Controller\FileWidgetAjaxController::progress()

Returns the progress status for a file upload process.

Parameters

string $key: The unique key for this upload process.

Return value

\Symfony\Component\HttpFoundation\JsonResponse A JsonResponse object.

1 string reference to 'FileWidgetAjaxController::progress'
file.routing.yml in core/modules/file/file.routing.yml
core/modules/file/file.routing.yml

File

core/modules/file/src/Controller/FileWidgetAjaxController.php, line 24

Class

FileWidgetAjaxController
Defines a controller to respond to file widget AJAX requests.

Namespace

Drupal\file\Controller

Code

public function progress($key) {
    $progress = [
        'message' => $this->t('Starting upload...'),
        'percentage' => -1,
    ];
    if (extension_loaded('uploadprogress')) {
        $status = uploadprogress_get_info($key);
        if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) {
            $progress['message'] = $this->t('Uploading... (@current of @total)', [
                '@current' => ByteSizeMarkup::create($status['bytes_uploaded']),
                '@total' => ByteSizeMarkup::create($status['bytes_total']),
            ]);
            $progress['percentage'] = round(100 * $status['bytes_uploaded'] / $status['bytes_total']);
        }
    }
    return new JsonResponse($progress);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.