FileWidgetAjaxController.php in Drupal 9
File
core/modules/file/src/Controller/FileWidgetAjaxController.php
View source
<?php
namespace Drupal\file\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
class FileWidgetAjaxController {
public function progress($key) {
$progress = [
'message' => t('Starting upload...'),
'percentage' => -1,
];
$implementation = file_progress_implementation();
if ($implementation == 'uploadprogress') {
$status = uploadprogress_get_info($key);
if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) {
$progress['message'] = t('Uploading... (@current of @total)', [
'@current' => format_size($status['bytes_uploaded']),
'@total' => format_size($status['bytes_total']),
]);
$progress['percentage'] = round(100 * $status['bytes_uploaded'] / $status['bytes_total']);
}
}
return new JsonResponse($progress);
}
}