download.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Download script for course info
  5. * @package chamilo.course_info
  6. */
  7. require_once '../inc/global.inc.php';
  8. $this_section = SECTION_COURSES;
  9. if (isset($_GET['session']) && $_GET['session']) {
  10. $archive_path = api_get_path(SYS_ARCHIVE_PATH).'temp/';
  11. $_cid = true;
  12. $is_courseAdmin = true;
  13. } else {
  14. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  15. }
  16. $archive_file = isset($_GET['archive']) ? $_GET['archive'] : null;
  17. $archive_file = str_replace(array('..', '/', '\\'), '', $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, array('xml', 'csv')) && (api_is_platform_admin(true) || api_is_drh())) {
  25. $content_type = 'application/force-download';
  26. } elseif ($extension == 'zip' && $_cid && (api_is_platform_admin(true) || $is_courseAdmin)) {
  27. $content_type = 'application/force-download';
  28. }
  29. if (empty($content_type)) {
  30. api_not_allowed(true);
  31. }
  32. if (Security::check_abs_path($archive_path.$archive_file, $archive_path)) {
  33. DocumentManager::file_send_for_download($archive_path.$archive_file, true, $archive_file);
  34. exit;
  35. } else {
  36. api_not_allowed(true);
  37. }