upload.xajax.php 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * @package chamilo.library
  4. */
  5. /**
  6. * Code
  7. */
  8. include(dirname(__FILE__).'/../global.inc.php');
  9. $xajax_upload = new Xajax();
  10. $xajax_upload -> registerFunction ('updateProgress');
  11. $xajax_upload -> processRequests();
  12. /**
  13. * This function updates the progress bar
  14. * @param div_id where the progress bar is displayed
  15. * @param upload_id the identifier given in the field UPLOAD_IDENTIFIER
  16. */
  17. function updateProgress($div_id, $upload_id, $waitAfterupload = false) {
  18. $objResponse = new xajaxResponse();
  19. $ul_info = uploadprogress_get_info($upload_id);
  20. $percent = intval($ul_info['bytes_uploaded']*100/$ul_info['bytes_total']);
  21. if($waitAfterupload && $ul_info['est_sec']<2) {
  22. $percent = 100;
  23. $objResponse -> addAssign($div_id.'_label' , 'innerHTML', get_lang('UploadFile').' : '.$percent.' %');
  24. $objResponse -> addAssign($div_id.'_waiter_frame','innerHTML','<img src="'.api_get_path(WEB_CODE_PATH).'img/progress_bar.gif" />');
  25. $objResponse -> addScript('clearInterval("myUpload.__progress_bar_interval")');
  26. }
  27. $objResponse -> addAssign($div_id.'_label' , 'innerHTML', get_lang('UploadFile').' : '.$percent.' %');
  28. $objResponse -> addAssign($div_id.'_filled' , 'style.width', $percent.'%');
  29. return $objResponse;
  30. }