download.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
  4. /**
  5. * Download script for course info
  6. * @package chamilo.course_info
  7. */
  8. //require_once '../inc/global.inc.php';
  9. $this_section = SECTION_COURSES;
  10. $_cid = false;
  11. if (isset($_GET['session']) && $_GET['session']) {
  12. $archive_path = api_get_path(SYS_ARCHIVE_PATH).'temp/';
  13. $_cid = true;
  14. $is_courseAdmin = true;
  15. } else {
  16. $archive_path = CourseArchiver::getBackupDir();
  17. }
  18. $archive_file = isset($_GET['archive']) ? $_GET['archive'] : null;
  19. $archive_file = str_replace(array('..', '/', '\\'), '', $archive_file);
  20. list($extension) = getextension($archive_file);
  21. if (empty($extension) || !file_exists($archive_path.$archive_file)) {
  22. exit;
  23. }
  24. $extension = strtolower($extension);
  25. $content_type = '';
  26. if (in_array($extension, array('xml', 'csv')) && (api_is_platform_admin(true) || api_is_drh())) {
  27. $content_type = 'application/force-download';
  28. } elseif ($extension === 'zip' && $_cid && (api_is_platform_admin(true) || $is_courseAdmin)) {
  29. $content_type = 'application/force-download';
  30. }
  31. if (empty($content_type)) {
  32. api_not_allowed(true);
  33. }
  34. if (Security::check_abs_path($archive_path.$archive_file, $archive_path)) {
  35. DocumentManager::file_send_for_download($archive_path.$archive_file, true, $archive_file);
  36. exit;
  37. } else {
  38. api_not_allowed(true);
  39. }