download.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  24. $archive_file = $_GET['archive'];
  25. $archive_file = str_replace(array('..', '/', '\\'), '', $archive_file);
  26. list($extension) = getextension($archive_file);
  27. if (empty($extension) || !file_exists($archive_path.$archive_file)) {
  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($archive_path.$archive_file));
  46. header('Content-Disposition: attachment; filename='.$archive_file);
  47. readfile($archive_path.$archive_file);