download.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 __DIR__.'/../inc/global.inc.php';
  9. $this_section = SECTION_COURSES;
  10. if (isset($_GET['archive_path'])) {
  11. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  12. } else {
  13. $archive_path = CourseArchiver::getBackupDir();
  14. }
  15. $archive_file = isset($_GET['archive']) ? $_GET['archive'] : null;
  16. $archive_file = str_replace(array('..', '/', '\\'), '', $archive_file);
  17. list($extension) = getextension($archive_file);
  18. if (empty($extension) || !file_exists($archive_path.$archive_file)) {
  19. exit;
  20. }
  21. $extension = strtolower($extension);
  22. $content_type = '';
  23. if (in_array($extension, array('xml', 'csv')) && (api_is_platform_admin(true) || api_is_drh())) {
  24. $content_type = 'application/force-download';
  25. } elseif ($extension === 'zip' && $_cid && (api_is_platform_admin(true) || $is_courseAdmin)) {
  26. $content_type = 'application/force-download';
  27. }
  28. if (empty($content_type)) {
  29. api_not_allowed(true);
  30. }
  31. if (Security::check_abs_path($archive_path.$archive_file, $archive_path)) {
  32. DocumentManager::file_send_for_download($archive_path.$archive_file, true, $archive_file);
  33. exit;
  34. } else {
  35. api_not_allowed(true);
  36. }