download.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This file is responsible for passing requested documents to the browser.
  6. *
  7. * @package chamilo.document
  8. */
  9. session_cache_limiter('none');
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. $this_section = SECTION_COURSES;
  12. // Protection
  13. api_protect_course_script();
  14. if (!isset($_course)) {
  15. api_not_allowed(true);
  16. }
  17. $doc_url = $_GET['doc_url'];
  18. // Change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  19. $doc_url = str_replace('///', '&', $doc_url);
  20. // Still a space present? it must be a '+' (that got replaced by mod_rewrite)
  21. $doc_url = str_replace(' ', '+', $doc_url);
  22. $doc_url = str_replace(['../', '\\..', '\\0', '..\\'], ['', '', '', ''], $doc_url); //echo $doc_url;
  23. if (strpos($doc_url, '../') || strpos($doc_url, '/..')) {
  24. $doc_url = '';
  25. }
  26. $sys_course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/scorm';
  27. $user_id = api_get_user_id();
  28. /** @var learnpath $lp */
  29. $lp = Session::read('oLP');
  30. if ($lp) {
  31. $lp_id = $lp->get_id();
  32. $lp_item_id = $lp->current;
  33. $lp_item_info = new learnpathItem($lp_item_id);
  34. if (!empty($lp_item_info)) {
  35. $visible = learnpath::is_lp_visible_for_student($lp_id, $user_id);
  36. if ($visible) {
  37. Event::event_download($doc_url);
  38. if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
  39. $full_file_name = $sys_course_path.$doc_url;
  40. DocumentManager::file_send_for_download($full_file_name);
  41. exit;
  42. }
  43. }
  44. //}
  45. }
  46. }
  47. echo Display::return_message(get_lang('ProtectedDocument'), 'error');
  48. //api_not_allowed backbutton won't work.
  49. exit;