download.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. require '../inc/global.inc.php';
  21. $this_section = SECTION_COURSES;
  22. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  23. if(isset($_GET['session']) && $_GET['session'] == true ){
  24. $archive_path = api_get_path(SYS_ARCHIVE_PATH).'temp/';
  25. $_cid = true;
  26. $is_courseAdmin = true;
  27. } else {
  28. $archive_path = api_get_path(SYS_PATH).$archiveDirName.'/';
  29. }
  30. $archive_file = $_GET['archive'];
  31. $archive_file = str_replace(array('..', '/', '\\'), '', $archive_file);
  32. list($extension) = getextension($archive_file);
  33. if (empty($extension) || !file_exists($archive_path.$archive_file)) {
  34. exit();
  35. }
  36. $content_type = '';
  37. if (in_array(strtolower($extension), array('xml','csv')) && api_is_platform_admin(true)) {
  38. $content_type = 'application/force-download';
  39. }
  40. elseif (strtolower($extension) == 'zip' && $_cid && $is_courseAdmin) {
  41. $content_type = 'application/force-download';
  42. }
  43. if (empty($content_type)) {
  44. api_not_allowed(true);
  45. }
  46. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  47. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  48. header('Cache-Control: public');
  49. header('Pragma: no-cache');
  50. header('Content-Type: '.$content_type);
  51. header('Content-Length: '.filesize($archive_path.$archive_file));
  52. header('Content-Disposition: attachment; filename='.$archive_file);
  53. readfile($archive_path.$archive_file);