download.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file is responsible for passing requested documents to the browser.
  5. *
  6. * @package chamilo.document
  7. */
  8. /* FUNCTIONS */
  9. /* file_html_dynamic_parsing removed */
  10. /* Other functions updated and moved to lib/document.lib.php */
  11. /* MAIN CODE */
  12. session_cache_limiter('none');
  13. require_once '../inc/global.inc.php';
  14. $this_section = SECTION_COURSES;
  15. // Protection
  16. api_protect_course_script();
  17. if (!isset($_course)) {
  18. api_not_allowed(true);
  19. }
  20. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  21. $doc_url = $_GET['doc_url'];
  22. // Change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  23. $doc_url = str_replace('///', '&', $doc_url);
  24. // Still a space present? it must be a '+' (that got replaced by mod_rewrite)
  25. $doc_url = str_replace(' ', '+', $doc_url);
  26. $doc_url = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), $doc_url); //echo $doc_url;
  27. if (strpos($doc_url,'../') OR strpos($doc_url,'/..')) {
  28. $doc_url = '';
  29. }
  30. // Dealing with image included into survey: when users receive a link towards a
  31. // survey while not being authenticated on the plateform.
  32. // The administrator should probably be able to disable this code through admin
  33. // inteface.
  34. $refer_script = strrchr($_SERVER["HTTP_REFERER"], '/');
  35. $sys_course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  36. if (substr($refer_script, 0, 15) == '/fillsurvey.php') {
  37. $invitation = substr(strstr($refer_script, 'invitationcode='), 15);
  38. $course = strstr($refer_script, 'course=');
  39. $course = substr($course, 7, strpos($course, '&') - 7);
  40. include '../survey/survey.download.inc.php';
  41. $_course = check_download_survey($course, $invitation, $doc_url);
  42. $_course['path'] = $_course['directory'];
  43. } else {
  44. // If the rewrite rule asks for a directory, we redirect to the document explorer
  45. if (is_dir($sys_course_path.$doc_url)) {
  46. // Remove last slash if present
  47. // mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (René)
  48. while ($doc_url{$dul = strlen($doc_url) - 1} == '/') {
  49. $doc_url = substr($doc_url, 0, $dul);
  50. }
  51. // Group folder?
  52. $gid_req = ($_GET['gidReq']) ? '&gidReq='.Security::remove_XSS($_GET['gidReq']) : '';
  53. // Create the path
  54. $document_explorer = api_get_path(WEB_CODE_PATH).'document/document.php?curdirpath='.urlencode($doc_url).'&cidReq='.Security::remove_XSS($_GET['cidReq']).$gid_req;
  55. // Redirect
  56. header('Location: '.$document_explorer);
  57. }
  58. // Launch event
  59. event_download($doc_url);
  60. }
  61. if (Security::check_abs_path($sys_course_path.$doc_url, $sys_course_path.'/')) {
  62. $full_file_name = $sys_course_path.$doc_url;
  63. // Check visibility of document and paths
  64. if (!api_is_allowed_to_edit() && !DocumentManager::is_visible($doc_url, $_course, api_get_session_id())) {
  65. Display::display_error_message(get_lang('ProtectedDocument'));//api_not_allowed backbutton won't work.
  66. exit; // You shouldn't be here anyway.
  67. }
  68. DocumentManager::file_send_for_download($full_file_name);
  69. }
  70. exit;