download.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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) 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.document
  25. ==============================================================================
  26. */
  27. /*
  28. ==============================================================================
  29. MAIN CODE
  30. ==============================================================================
  31. */
  32. session_cache_limiter('public');
  33. include('../inc/global.inc.php');
  34. $this_section=SECTION_COURSES;
  35. include(api_get_path(LIBRARY_PATH).'document.lib.php');
  36. // IMPORTANT to avoid caching of documents
  37. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  38. header('Cache-Control: public');
  39. header('Pragma: no-cache');
  40. //protection
  41. api_protect_course_script(true);
  42. $doc_url = $_GET['file'];
  43. //change the '&' that got rewritten to '///' by mod_rewrite back to '&'
  44. $doc_url = str_replace('///', '&', $doc_url);
  45. //still a space present? it must be a '+' (that got replaced by mod_rewrite)
  46. $doc_url = str_replace(' ', '+', $doc_url);
  47. $doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
  48. include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  49. if (! isset($_course))
  50. {
  51. api_not_allowed(true);
  52. }
  53. $full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/blog/'.$doc_url;
  54. //if the rewrite rule asks for a directory, we redirect to the course view
  55. if (is_dir($full_file_name))
  56. {
  57. //remove last slash if present
  58. while ($doc_url{$dul = strlen($doc_url)-1}=='/') $doc_url = substr($doc_url,0,$dul);
  59. //create the path
  60. $document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
  61. //redirect
  62. header('Location: '.$document_explorer);
  63. }
  64. $tbl_blogs_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
  65. // launch event
  66. event_download($doc_url);
  67. $sql = 'SELECT filename FROM '.$tbl_blogs_attachment.' WHERE path LIKE BINARY "'.$doc_url.'"';
  68. $result= api_sql_query($sql, __FILE__, __LINE__);
  69. $row= Database::fetch_array($result);
  70. DocumentManager::file_send_for_download($full_file_name,TRUE, $row['filename']);
  71. exit;
  72. ?>