download.php 1.3 KB

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