diff --git a/core/misc/ajax.js b/core/misc/ajax.js
index fefe9f3..ef6f154 100644
--- a/core/misc/ajax.js
+++ b/core/misc/ajax.js
@@ -478,6 +478,9 @@
ajax.ajaxing = true;
return ajax.beforeSend(xmlhttprequest, options);
},
+ uploadProgress: function(event, position, total, percentComplete) {
+ ajax.uploadProgress(event, position, total, percentComplete);
+ },
success: function (response, status, xmlhttprequest) {
// Sanity check for browser support (object expected).
// When using iFrame uploads, responses must be returned as a string.
@@ -798,6 +801,20 @@
};
/**
+ * Processes file upload progress if needed.
+ * @param event
+ * @param position
+ * @param total
+ * @param percentComplete
+ */
+ Drupal.Ajax.prototype.uploadProgress = function (event, position, total, percentComplete) {
+ this.progress.object.setProgressdata({
+ loaded: position,
+ total: total
+ });
+ };
+
+ /**
* Sets the progress bar progress indicator.
*/
Drupal.Ajax.prototype.setProgressIndicatorBar = function () {
diff --git a/core/misc/progress.js b/core/misc/progress.js
index a669489..2b57f93 100644
--- a/core/misc/progress.js
+++ b/core/misc/progress.js
@@ -108,9 +108,17 @@
},
/**
+ * Set the sent progress data from ajax.js
+ */
+ setProgressdata: function (obj) {
+ this.progressdata = obj;
+ },
+
+ /**
* Request progress data from server.
*/
sendPing: function () {
+
if (this.timer) {
clearTimeout(this.timer);
}
@@ -126,10 +134,16 @@
uri += '&';
}
uri += '_format=json';
+
+ var extradata = {};
+ if (typeof this.progressdata != 'undefined') {
+ extradata = this.progressdata;
+ }
+
$.ajax({
type: this.method,
url: uri,
- data: '',
+ data: extradata,
dataType: 'json',
success: function (progress) {
// Display errors.
diff --git a/core/modules/file/file.install b/core/modules/file/file.install
index 05eedf0..eafa12a 100644
--- a/core/modules/file/file.install
+++ b/core/modules/file/file.install
@@ -63,60 +63,11 @@ function file_schema() {
* Display information about getting upload progress bars working.
*/
function file_requirements($phase) {
- $requirements = array();
-
- // Check the server's ability to indicate upload progress.
- if ($phase == 'runtime') {
- $description = NULL;
- $implementation = file_progress_implementation();
- $server_software = \Drupal::request()->server->get('SERVER_SOFTWARE');
-
- // Test the web server identity.
- if (preg_match("/Nginx/i", $server_software)) {
- $is_nginx = TRUE;
- $is_apache = FALSE;
- $fastcgi = FALSE;
- }
- elseif (preg_match("/Apache/i", $server_software)) {
- $is_nginx = FALSE;
- $is_apache = TRUE;
- $fastcgi = strpos($server_software, 'mod_fastcgi') !== FALSE || strpos($server_software, 'mod_fcgi') !== FALSE;
- }
- else {
- $is_nginx = FALSE;
- $is_apache = FALSE;
- $fastcgi = FALSE;
- }
-
- if (!$is_apache && !$is_nginx) {
- $value = t('Not enabled');
- $description = t('Your server is not capable of displaying file upload progress. File upload progress requires an Apache server running PHP with mod_php or Nginx with PHP-FPM.');
- }
- elseif ($fastcgi) {
- $value = t('Not enabled');
- $description = t('Your server is not capable of displaying file upload progress. File upload progress requires PHP be run with mod_php or PHP-FPM and not as FastCGI.');
- }
- elseif (!$implementation && extension_loaded('apcu')) {
- $value = t('Not enabled');
- $description = t('Your server is capable of displaying file upload progress through APC, but it is not enabled. Add apc.rfc1867 = 1
to your php.ini configuration. Alternatively, it is recommended to use PECL uploadprogress, which supports more than one simultaneous upload.');
- }
- elseif (!$implementation) {
- $value = t('Not enabled');
- $description = t('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the PECL uploadprogress library (preferred) or to install APC.');
- }
- elseif ($implementation == 'apc') {
- $value = t('Enabled (APC RFC1867)');
- $description = t('Your server is capable of displaying file upload progress using APC RFC1867. Note that only one upload at a time is supported. It is recommended to use the PECL uploadprogress library if possible.');
- }
- elseif ($implementation == 'uploadprogress') {
- $value = t('Enabled (PECL uploadprogress)');
- }
- $requirements['file_progress'] = array(
+ return array(
+ 'file_progress' => array(
'title' => t('Upload progress'),
- 'value' => $value,
- 'description' => $description,
- );
- }
-
- return $requirements;
+ 'value' => t('jQuery.form uploadProgress'),
+ 'description' => t('Drupal 8 uses client side jQuery.form uploadProgress. No extensions are required.'),
+ ),
+ );
}
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index c63fff4..dbbfb76 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -913,27 +913,14 @@ function file_save_upload($form_field_name, $validators = array(), $destination
}
/**
- * Determines the preferred upload progress implementation.
+ * Determines the preferred upload progress implementation. Drupal 8 now uses
+ * ajax.form for the upload progress, so this function is here for backward
+ * compatibility.
*
- * @return string|false
- * A string indicating which upload progress system is available. Either "apc"
- * or "uploadprogress". If neither are available, returns FALSE.
+ * @return bool|false
*/
function file_progress_implementation() {
- static $implementation;
- if (!isset($implementation)) {
- $implementation = FALSE;
-
- // We prefer the PECL extension uploadprogress because it supports multiple
- // simultaneous uploads. APCu only supports one at a time.
- if (extension_loaded('uploadprogress')) {
- $implementation = 'uploadprogress';
- }
- elseif (extension_loaded('apc') && ini_get('apc.rfc1867')) {
- $implementation = 'apc';
- }
- }
- return $implementation;
+ return TRUE;
}
/**
diff --git a/core/modules/file/src/Controller/FileWidgetAjaxController.php b/core/modules/file/src/Controller/FileWidgetAjaxController.php
index d5c6874..338c1b3 100644
--- a/core/modules/file/src/Controller/FileWidgetAjaxController.php
+++ b/core/modules/file/src/Controller/FileWidgetAjaxController.php
@@ -24,20 +24,9 @@ public function progress($key) {
'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']);
- }
+ if (isset($_GET['loaded']) && isset($_GET['total'])) {
+ $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($_GET['loaded']), '@total' => format_size($_GET['total'])));
+ $progress['percentage'] = round(100 * $_GET['loaded'] / $_GET['total']);
}
return new JsonResponse($progress);
diff --git a/core/modules/file/src/Element/ManagedFile.php b/core/modules/file/src/Element/ManagedFile.php
index f465b18..62beb0b 100644
--- a/core/modules/file/src/Element/ManagedFile.php
+++ b/core/modules/file/src/Element/ManagedFile.php
@@ -269,30 +269,9 @@ public static function processManagedFile(&$element, FormStateInterface $form_st
];
// Add progress bar support to the upload if possible.
- if ($element['#progress_indicator'] == 'bar' && $implementation = file_progress_implementation()) {
+ if ($element['#progress_indicator'] == 'bar') {
$upload_progress_key = mt_rand();
- if ($implementation == 'uploadprogress') {
- $element['UPLOAD_IDENTIFIER'] = [
- '#type' => 'hidden',
- '#value' => $upload_progress_key,
- '#attributes' => ['class' => ['file-progress']],
- // Uploadprogress extension requires this field to be at the top of
- // the form.
- '#weight' => -20,
- ];
- }
- elseif ($implementation == 'apc') {
- $element['APC_UPLOAD_PROGRESS'] = [
- '#type' => 'hidden',
- '#value' => $upload_progress_key,
- '#attributes' => ['class' => ['file-progress']],
- // Uploadprogress extension requires this field to be at the top of
- // the form.
- '#weight' => -20,
- ];
- }
-
// Add the upload progress callback.
$element['upload_button']['#ajax']['progress']['url'] = Url::fromRoute('file.ajax_progress', ['key' => $upload_progress_key]);
}