upload.xajax.php 1.3 KB

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