You are here

function itweak_upload_progress in iTweak Upload 6.2

Menu callback for upload progress.

1 string reference to 'itweak_upload_progress'
itweak_upload_menu in ./itweak_upload.module
Implementation of hook_menu().

File

./itweak_upload.module, line 1408
iTweakUpload - Tweak attachments display and file upload forms.

Code

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