upload.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../../main/inc/global.inc.php';
  4. api_protect_course_script();
  5. $plugin = new AppPlugin();
  6. $pluginList = $plugin->getInstalledPlugins();
  7. $capturePluginInstalled = in_array('jcapture', $pluginList);
  8. if (!$capturePluginInstalled) {
  9. exit;
  10. }
  11. if (!isset($_FILES['Filedata'])) {
  12. exit;
  13. }
  14. $courseInfo = api_get_course_info();
  15. $folderName = 'captures';
  16. $documentId = DocumentManager::get_document_id($courseInfo, '/'.$folderName);
  17. $path = null;
  18. if (empty($documentId)) {
  19. $course_dir = $courseInfo['path'].'/document';
  20. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  21. $dir = $sys_course_path.$course_dir;
  22. $createdDir = create_unexisting_directory(
  23. $courseInfo,
  24. api_get_user_id(),
  25. api_get_session_id(),
  26. null,
  27. null,
  28. $dir,
  29. '/'.$folderName,
  30. $folderName
  31. );
  32. if ($createdDir) {
  33. $path = '/'.$folderName;
  34. }
  35. } else {
  36. $data = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
  37. $path = $data['path'];
  38. }
  39. if (empty($path)) {
  40. exit;
  41. }
  42. $files = [
  43. 'file' => $_FILES['Filedata'],
  44. ];
  45. DocumentManager::upload_document(
  46. $files,
  47. $path,
  48. $_FILES['Filedata']['name'],
  49. null,
  50. false,
  51. 'rename',
  52. false,
  53. true
  54. );