download.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php // $Id: $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  14. info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * This file is responsible for passing requested documents to the browser.
  20. * Html files are parsed to fix a few problems with URLs,
  21. * but this code will hopefully be replaced soon by an Apache URL
  22. * rewrite mechanism.
  23. *
  24. * @package dokeos.calendar
  25. ==============================================================================
  26. */
  27. /*
  28. ==============================================================================
  29. MAIN CODE
  30. ==============================================================================
  31. */
  32. session_cache_limiter('public');
  33. require_once '../inc/global.inc.php';
  34. $this_section=SECTION_COURSES;
  35. require_once api_get_path(LIBRARY_PATH).'document.lib.php';
  36. require_once 'agenda.inc.php';
  37. // IMPORTANT to avoid caching of documents
  38. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  39. header('Cache-Control: public');
  40. header('Pragma: no-cache');
  41. //protection
  42. api_protect_course_script(true);
  43. $doc_url = $_GET['file'];
  44. //change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  45. $doc_url = str_replace('///', '&', $doc_url);
  46. //still a space present? it must be a '+' (that got replaced by mod_rewrite)
  47. $doc_url = str_replace(' ', '+', $doc_url);
  48. $doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
  49. if (!isset($_course)) {
  50. api_not_allowed(true);
  51. }
  52. $full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/calendar/'.$doc_url;
  53. //if the rewrite rule asks for a directory, we redirect to the document explorer
  54. if (is_dir($full_file_name))
  55. {
  56. //remove last slash if present
  57. //$doc_url = ($doc_url{strlen($doc_url)-1}=='/')?substr($doc_url,0,strlen($doc_url)-1):$doc_url;
  58. //mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (Ren�)
  59. while ($doc_url{$dul = strlen($doc_url)-1}=='/') $doc_url = substr($doc_url,0,$dul);
  60. //create the path
  61. $document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
  62. //redirect
  63. header('Location: '.$document_explorer);
  64. }
  65. $tbl_agenda_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
  66. // launch event
  67. event_download($doc_url);
  68. $sql='SELECT filename FROM '.$tbl_agenda_attachment.'
  69. WHERE path LIKE BINARY "'.$doc_url.'"';
  70. $result= api_sql_query($sql, __FILE__, __LINE__);
  71. $row= Database::fetch_array($result);
  72. $title = str_replace(' ','_', $row['filename']);
  73. DocumentManager::file_send_for_download($full_file_name,TRUE, $title);
  74. exit;
  75. ?>