download.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. //session_cache_limiter('public');
  4. require '../inc/global.inc.php';
  5. $this_section = SECTION_COURSES;
  6. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  7. if(isset($_GET['session']) && $_GET['session'] == true ){
  8. $archive_path = api_get_path(SYS_ARCHIVE_PATH).'temp/';
  9. $_cid = true;
  10. $is_courseAdmin = true;
  11. } else {
  12. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  13. }
  14. $archive_file = $_GET['archive'];
  15. $archive_file = str_replace(array('..', '/', '\\'), '', $archive_file);
  16. list($extension) = getextension($archive_file);
  17. if (empty($extension) || !file_exists($archive_path.$archive_file)) {
  18. exit();
  19. }
  20. $content_type = '';
  21. if (in_array(strtolower($extension), array('xml','csv')) && (api_is_platform_admin(true) || api_is_drh())) {
  22. $content_type = 'application/force-download';
  23. }
  24. elseif (strtolower($extension) == 'zip' && $_cid && (api_is_platform_admin(true) || $is_courseAdmin)) {
  25. $content_type = 'application/force-download';
  26. }
  27. if (empty($content_type)) {
  28. api_not_allowed(true);
  29. }
  30. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  31. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  32. header('Cache-Control: public');
  33. header('Pragma: no-cache');
  34. header('Content-Type: '.$content_type);
  35. header('Content-Length: '.filesize($archive_path.$archive_file));
  36. header('Content-Disposition: attachment; filename='.$archive_file);
  37. readfile($archive_path.$archive_file);