When site has enabled page cache and anonymous user tries to upload a file, he cannot see upload status progress. He see only message "Starting upload...". Bug was reported in June 2012, has a working patch and I have a question:

How to fix broken file.module function file_ajax_progress without hacking the core and patching after every update? Should I do some function override by custom module?

This is all working code together:

 * Menu callback for upload progress.
 * @param $key
 *   The unique key for this upload process.
function file_ajax_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 = apc_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']);
  // Mark this page as being uncacheable.

2 Answers 2


Patching core is not the same as hacking core. Many of us have patched versions of Drupal in the wild (eg, using Secure Pages).

You need to work out how you want to manage this between upgrades.

On sites where I don't track Drupal's repo, I keep a directory of patches next to the DOCROOT. Before I upgrade, I check on whether the patch is needed or not. I then drush pm-update drupal and apply patches.

On sites that I have built with git, I can typically build the site in its own branch, apply patches, and then upgrade core versions by merging the latest tag and doing the database updates.

  • 1th. Thank you. 2nd. You basically wrote: refix it after every update. I think, it's not the best possible option. I have updated my question. Commented Oct 31, 2015 at 3:29

The answer is simple: make a module. So I created one. Module has name Upload progress fix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.