download.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. if (! isset($_course))
  49. {
  50. api_not_allowed(true);
  51. }
  52. $full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/blog/'.$doc_url;
  53. //if the rewrite rule asks for a directory, we redirect to the course view
  54. if (is_dir($full_file_name))
  55. {
  56. //remove last slash if present
  57. while ($doc_url{$dul = strlen($doc_url)-1}=='/') $doc_url = substr($doc_url,0,$dul);
  58. //create the path
  59. $document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
  60. //redirect
  61. header('Location: '.$document_explorer);
  62. }
  63. $tbl_blogs_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
  64. // launch event
  65. event_download($doc_url);
  66. $sql = 'SELECT filename FROM '.$tbl_blogs_attachment.' WHERE path LIKE BINARY "'.$doc_url.'"';
  67. $result= api_sql_query($sql, __FILE__, __LINE__);
  68. $row= Database::fetch_array($result);
  69. DocumentManager::file_send_for_download($full_file_name,TRUE, $row['filename']);
  70. exit;
  71. ?>