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. * @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')) &&
  24. (api_is_platform_admin(true) || api_is_drh())
  25. ) {
  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. DocumentManager::file_send_for_download(
  35. $archive_path.$archive_file,
  36. true,
  37. $archive_file
  38. );
  39. exit;
  40. } else {
  41. api_not_allowed(true);
  42. }