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