public FileWidgetAjaxController::progress($key)
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.
File
- core/modules/file/src/Controller/FileWidgetAjaxController.php, line 21
Class
- FileWidgetAjaxController
- Defines a controller to respond to file widget AJAX requests.
Namespace
Drupal\file\Controller
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public function progress( $key ) { $progress = array ( '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)' , array ( '@current' => format_size( $status [ 'bytes_uploaded' ]), '@total' => format_size( $status [ 'bytes_total' ]))); $progress [ 'percentage' ] = round (100 * $status [ 'bytes_uploaded' ] / $status [ 'bytes_total' ]); } } elseif ( $implementation == 'apc' ) { $status = apcu_fetch( 'upload_' . $key ); if (isset( $status [ 'current' ]) && ! empty ( $status [ 'total' ])) { $progress [ 'message' ] = t( 'Uploading... (@current of @total)' , array ( '@current' => format_size( $status [ 'current' ]), '@total' => format_size( $status [ 'total' ]))); $progress [ 'percentage' ] = round (100 * $status [ 'current' ] / $status [ 'total' ]); } } return new JsonResponse( $progress ); } |
Please login to continue.