download.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file is responsible for passing requested documents to the browser.
  5. * Html files are parsed to fix a few problems with URLs,
  6. * but this code will hopefully be replaced soon by an Apache URL
  7. * rewrite mechanism.
  8. *
  9. * @package chamilo.work
  10. */
  11. session_cache_limiter('public');
  12. require_once '../inc/global.inc.php';
  13. $this_section = SECTION_COURSES;
  14. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  15. // IMPORTANT to avoid caching of documents
  16. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  17. header('Cache-Control: public');
  18. header('Pragma: no-cache');
  19. //protection
  20. api_protect_course_script(true);
  21. $doc_url = $_GET['file'];
  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('/..', '', $doc_url); //echo $doc_url;
  27. if (!isset($_course)) {
  28. api_not_allowed(true);
  29. }
  30. $full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.$doc_url;
  31. $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  32. // launch event
  33. event_download($doc_url);
  34. $doc_url = Database::escape_string($doc_url);
  35. $sql = 'SELECT title FROM '.$tbl_student_publication.'WHERE url LIKE BINARY "'.$doc_url.'"';
  36. $result = Database::query($sql);
  37. if (Database::num_rows($result) > 0) {
  38. $row = Database::fetch_array($result);
  39. $title = str_replace(' ', '_', $row['title']);
  40. if (Security::check_abs_path($full_file_name, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/')) {
  41. DocumentManager::file_send_for_download($full_file_name, true, $title);
  42. }
  43. }
  44. exit;