download.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php // $Id: download.php 9246 2006-09-25 13:24:53Z bmol $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. session_cache_limiter('public');
  20. include('../inc/global.inc.php');
  21. $this_section=SECTION_COURSES;
  22. include_once(api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  23. $archivePath=api_get_path(SYS_PATH).$archiveDirName.'/';
  24. $archiveFile=$_GET['archive'];
  25. $archiveFile=str_replace(array('..','/','\\'),'',$archiveFile);
  26. list($extension)=getextension($archiveFile);
  27. if(empty($extension) || !file_exists($archivePath.$archiveFile))
  28. {
  29. exit();
  30. }
  31. $content_type='';
  32. if(in_array($extension,array('xml','csv')) && $is_platformAdmin)
  33. {
  34. $content_type='application/force-download';
  35. }
  36. elseif($extension == 'zip' && $_cid && $is_courseAdmin)
  37. {
  38. $content_type='application/force-download';
  39. }
  40. if(empty($content_type))
  41. {
  42. not_allowed();
  43. }
  44. header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
  45. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  46. header('Cache-Control: public');
  47. header('Pragma: no-cache');
  48. header('Content-Type: '.$content_type);
  49. header('Content-Length: '.filesize($archivePath.$archiveFile));
  50. header('Content-Disposition: attachment; filename='.$archiveFile);
  51. readfile($archivePath.$archiveFile);
  52. ?>