dokeos-document
[ class tree: dokeos-document ] [ index: dokeos-document ] [ all elements ]

Source for file download.php

Documentation is available at download.php

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

Documentation generated on Thu, 12 Jun 2008 13:20:35 -0500 by phpDocumentor 1.4.1