download.php 1.7 KB

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