download.php 1.6 KB

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