lp_upload.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php //$id: $
  2. /**
  3. * Script managing the learnpath upload. To best treat the uploaded file, make sure we can identify it.
  4. * @package dokeos.learnpath
  5. * @author Yannick Warnier <ywarnier@beeznest.org>
  6. */
  7. /**
  8. * Script initialisations
  9. */
  10. //$langFile = "scormdocument";
  11. require_once('back_compat.inc.php');
  12. $course_dir = api_get_course_path().'/scorm';
  13. $course_sys_dir = api_get_path(SYS_COURSE_PATH).$course_dir;
  14. $current_dir = replace_dangerous_char(trim($_POST['current_dir']),'strict');
  15. $uncompress = 1;
  16. //error_log('New LP - lp_upload.php',0);
  17. /*
  18. * check the request method in place of a variable from POST
  19. * because if the file size exceed the maximum file upload
  20. * size set in php.ini, all variables from POST are cleared !
  21. */
  22. if ($_SERVER['REQUEST_METHOD'] == 'POST'
  23. && count($_FILES)>0
  24. && empty($_POST['file_name'])
  25. )
  26. {
  27. // A file upload has been detected, now deal with the file...
  28. //directory creation
  29. $stopping_error = false;
  30. $s=$_FILES['user_file']['name'];
  31. //get name of the zip file without the extension
  32. $info = pathinfo($s);
  33. $filename = $info['basename'];
  34. $extension = $info['extension'];
  35. $file_base_name = str_replace('.'.$extension,'',$filename);
  36. $new_dir = replace_dangerous_char(trim($file_base_name),'strict');
  37. require_once('learnpath.class.php');
  38. require_once('scorm.class.php');
  39. $oScorm = new scorm();
  40. $manifest = $oScorm->import_package($_FILES['user_file'],$current_dir);
  41. if(!empty($manifest)){
  42. $oScorm->parse_manifest($manifest);
  43. $oScorm->import_manifest(api_get_course_id());
  44. }
  45. $proximity = '';
  46. if(!empty($_REQUEST['content_proximity'])){$proximity = mysql_real_escape_string($_REQUEST['content_proximity']);}
  47. $maker = '';
  48. if(!empty($_REQUEST['content_maker'])){$maker = mysql_real_escape_string($_REQUEST['content_maker']);}
  49. $oScorm->set_proximity($proximity);
  50. $oScorm->set_maker($maker);
  51. $oScorm->set_jslib('scorm_api.php');
  52. } // end if is_uploaded_file
  53. elseif($_SERVER['REQUEST_METHOD'] == 'POST')
  54. {
  55. //if file name given to get in claroline/upload/, try importing this way
  56. // A file upload has been detected, now deal with the file...
  57. //directory creation
  58. $stopping_error = false;
  59. //escape path with basename so it can only be directly into the claroline/upload directory
  60. $s=api_get_path(SYS_CODE_PATH).'garbage/'.basename($_POST['file_name']);
  61. //get name of the zip file without the extension
  62. $info = pathinfo($s);
  63. $filename = $info['basename'];
  64. $extension = $info['extension'];
  65. $file_base_name = str_replace('.'.$extension,'',$filename);
  66. $new_dir = replace_dangerous_char(trim($file_base_name),'strict');
  67. require_once('learnpath.class.php');
  68. require_once('scorm.class.php');
  69. $oScorm = new scorm();
  70. $manifest = $oScorm->import_local_package($s,$current_dir);
  71. if(!empty($manifest)){
  72. $oScorm->parse_manifest($manifest);
  73. $oScorm->import_manifest(api_get_course_id());
  74. }
  75. $proximity = '';
  76. if(!empty($_REQUEST['content_proximity'])){$proximity = mysql_real_escape_string($_REQUEST['content_proximity']);}
  77. $maker = '';
  78. if(!empty($_REQUEST['content_maker'])){$maker = mysql_real_escape_string($_REQUEST['content_maker']);}
  79. $oScorm->set_proximity($proximity);
  80. $oScorm->set_maker($maker);
  81. $oScorm->set_jslib('scorm_api.php');
  82. }
  83. ?>