download.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php // $Id: download.php 17989 2009-01-25 05:51:54Z yannoo $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. * This file is responsible for passing requested documents to the browser.
  6. * Html files are parsed to fix a few problems with URLs,
  7. * but this code will hopefully be replaced soon by an Apache URL
  8. * rewrite mechanism.
  9. *
  10. * @package dokeos.work
  11. ==============================================================================
  12. */
  13. /*
  14. ==============================================================================
  15. MAIN CODE
  16. ==============================================================================
  17. */
  18. session_cache_limiter('public');
  19. require '../inc/global.inc.php';
  20. $this_section=SECTION_COURSES;
  21. require_once(api_get_path(LIBRARY_PATH).'document.lib.php');
  22. require (api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  23. //include 'agenda.inc.php';
  24. // IMPORTANT to avoid caching of documents
  25. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  26. header('Cache-Control: public');
  27. header('Pragma: no-cache');
  28. //protection
  29. api_protect_course_script(true);
  30. $doc_url = $_GET['file'];
  31. //change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  32. $doc_url = str_replace('///', '&', $doc_url);
  33. //still a space present? it must be a '+' (that got replaced by mod_rewrite)
  34. $doc_url = str_replace(' ', '+', $doc_url);
  35. $doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
  36. if (! isset($_course)) {
  37. api_not_allowed(true);
  38. }
  39. $full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.$doc_url;
  40. $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
  41. // launch event
  42. event_download($doc_url);
  43. $sql='SELECT title FROM '.$tbl_student_publication.'
  44. WHERE url LIKE BINARY "'.$doc_url.'"';
  45. $result= api_sql_query($sql, __FILE__, __LINE__);
  46. $row= Database::fetch_array($result);
  47. $title = str_replace(' ','_', $row['title']);
  48. DocumentManager::file_send_for_download($full_file_name,TRUE, $title);
  49. exit;
  50. ?>