download.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Download script for course info
  5. * @package chamilo.course_info
  6. */
  7. /**
  8. * Code
  9. */
  10. //session_cache_limiter('public');
  11. require_once '../inc/global.inc.php';
  12. $this_section = SECTION_COURSES;
  13. if ($_GET['session']) {
  14. $archive_path = api_get_path(SYS_ARCHIVE_PATH).'temp/';
  15. $_cid = true;
  16. $is_courseAdmin = true;
  17. } else {
  18. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  19. }
  20. $archive_file = $_GET['archive'];
  21. $archive_file = str_replace(array('..', '/', '\\'), '', $archive_file);
  22. list($extension) = getextension($archive_file);
  23. if (empty($extension) || !file_exists($archive_path.$archive_file)) {
  24. exit;
  25. }
  26. $extension = strtolower($extension);
  27. $content_type = '';
  28. if (in_array($extension, array('xml', 'csv')) && (api_is_platform_admin(true) || api_is_drh())) {
  29. $content_type = 'application/force-download';
  30. } elseif ($extension == 'zip' && $_cid && (api_is_platform_admin(true) || $is_courseAdmin)) {
  31. $content_type = 'application/force-download';
  32. }
  33. if (empty($content_type)) {
  34. api_not_allowed(true);
  35. }
  36. if (Security::check_abs_path($archive_path.$archive_file, $archive_path)) {
  37. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  38. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  39. header('Cache-Control: public');
  40. header('Pragma: no-cache');
  41. header('Content-Type: '.$content_type);
  42. header('Content-Length: '.filesize($archive_path.$archive_file));
  43. header('Content-Disposition: attachment; filename='.$archive_file);
  44. readfile($archive_path.$archive_file);
  45. } else {
  46. api_not_allowed(true);
  47. }