upload.php 1.4 KB

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