download.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php // $Id: download.php 12218 2007-05-01 18:27:14Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Olivier Brouckaert
  9. Copyright (c) Roan Embrechts
  10. Copyright (c) Sergio A. Kessler aka "sak"
  11. For a full list of contributors, see "credits.txt".
  12. The full license can be read in "license.txt".
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. See the GNU General Public License for more details.
  18. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * This file is responsible for passing requested documents to the browser.
  24. * Html files are parsed to fix a few problems with URLs,
  25. * but this code will hopefully be replaced soon by an Apache URL
  26. * rewrite mechanism.
  27. *
  28. * @package dokeos.document
  29. ==============================================================================
  30. */
  31. /*
  32. ==============================================================================
  33. FUNCTIONS
  34. ==============================================================================
  35. */
  36. /* file_html_dynamic_parsing removed */
  37. /* other functions updated and moved to lib/document.lib.php */
  38. /*
  39. ==============================================================================
  40. MAIN CODE
  41. ==============================================================================
  42. */
  43. session_cache_limiter('public');
  44. include('../inc/global.inc.php');
  45. $this_section=SECTION_COURSES;
  46. include(api_get_path(LIBRARY_PATH).'document.lib.php');
  47. // IMPORTANT to avoid caching of documents
  48. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  49. header('Cache-Control: public');
  50. header('Pragma: no-cache');
  51. //protection
  52. api_protect_course_script();
  53. $doc_url = $_GET['doc_url'];
  54. //change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  55. $doc_url = str_replace('///', '&', $doc_url);
  56. //still a space present? it must be a '+' (that got replaced by mod_rewrite)
  57. $doc_url = str_replace(' ', '+', $doc_url);
  58. $doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
  59. include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  60. if (! isset($_course))
  61. {
  62. api_not_allowed(true);
  63. }
  64. //if the rewrite rule asks for a directory, we redirect to the document explorer
  65. if(is_dir(api_get_path(SYS_COURSE_PATH).$_course['path']."/document".$doc_url))
  66. {
  67. //remove last slash if present
  68. //$doc_url = ($doc_url{strlen($doc_url)-1}=='/')?substr($doc_url,0,strlen($doc_url)-1):$doc_url;
  69. //mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (René)
  70. while ($doc_url{$dul = strlen($doc_url)-1}=='/') $doc_url = substr($doc_url,0,$dul);
  71. //group folder?
  72. $gid_req = ($_GET['gidReq'])?'&gidReq='.$_GET['gidReq']:'';
  73. //create the path
  74. $document_explorer = api_get_path(WEB_CODE_PATH).'document/document.php?curdirpath='.urlencode($doc_url).'&cidReq='.$_GET['cidReq'].$gid_req;
  75. //redirect
  76. header('Location: '.$document_explorer);
  77. }
  78. // launch event
  79. event_download($doc_url);
  80. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  81. $full_file_name = $sys_course_path.$_course['path'].'/document'.$doc_url;
  82. DocumentManager::file_send_for_download($full_file_name);
  83. ?>