file_ajax_progress function fix (Progress bar freeze for anonymous users when cache is enabled)

Public

file_ajax_progress function fix (Progress bar freeze for anonymous users when cache is enabled). See more at https://drupal.stackexchange.com/q/179313/13287 and https://www.drupal.org/node/1627162

Get raw version
php
  1. /**
  2.  * Menu callback for upload progress.
  3.  *
  4.  * @param $key
  5.  * The unique key for this upload process.
  6.  */
  7. function file_ajax_progress($key) {
  8. $progress = array(
  9. 'message' => t('Starting upload...'),
  10. 'percentage' => -1,
  11. );
  12.  
  13. $implementation = file_progress_implementation();
  14. if ($implementation == 'uploadprogress') {
  15. $status = uploadprogress_get_info($key);
  16. if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) {
  17. $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($status['bytes_uploaded']), '@total' => format_size($status['bytes_total'])));
  18. $progress['percentage'] = round(100 * $status['bytes_uploaded'] / $status['bytes_total']);
  19. }
  20. }
  21. elseif ($implementation == 'apc') {
  22. $status = apc_fetch('upload_' . $key);
  23. if (isset($status['current']) && !empty($status['total'])) {
  24. $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($status['current']), '@total' => format_size($status['total'])));
  25. $progress['percentage'] = round(100 * $status['current'] / $status['total']);
  26. }
  27. }
  28. // Mark this page as being uncacheable.
  29. drupal_page_is_cacheable(FALSE);
  30. drupal_json_output($progress);
  31. }