You are here

function filefield_progress in FileField 6.3

Menu callback for upload progress.

1 string reference to 'filefield_progress'
filefield_menu in ./filefield.module
Implementation of hook_menu().

File

./filefield.module, line 679
FileField: Defines a CCK file field type.

Code

function filefield_progress($key) {
  $progress = array(
    'message' => t('Starting upload...'),
    'percentage' => -1,
  );
  $implementation = filefield_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']);
    }
  }
  drupal_json($progress);
}