download.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php // $Id: download.php 21562 2009-06-22 10:38:38Z ivantcholakov $
  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. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. session_cache_limiter('public');
  20. include('../inc/global.inc.php');
  21. $this_section=SECTION_COURSES;
  22. include_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  23. $archivePath = api_get_path(SYS_PATH).$archiveDirName.'/';
  24. $archiveFile = $_GET['archive'];
  25. $archiveFile = str_replace(array('..', '/', '\\'), '', $archiveFile);
  26. list($extension) = getextension($archiveFile);
  27. if (empty($extension) || !file_exists($archivePath.$archiveFile)) {
  28. exit();
  29. }
  30. $content_type = '';
  31. if (in_array(strtolower($extension), array('xml','csv')) && api_is_platform_admin(true)) {
  32. $content_type='application/force-download';
  33. }
  34. elseif (strtolower($extension) == 'zip' && $_cid && $is_courseAdmin) {
  35. $content_type='application/force-download';
  36. }
  37. if (empty($content_type)) {
  38. api_not_allowed(true);
  39. }
  40. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  41. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  42. header('Cache-Control: public');
  43. header('Pragma: no-cache');
  44. header('Content-Type: '.$content_type);
  45. header('Content-Length: '.filesize($archivePath.$archiveFile));
  46. header('Content-Disposition: attachment; filename='.$archiveFile);
  47. readfile($archivePath.$archiveFile);
  48. ?>