receiver.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file allows creating new svg and png documents with an online editor.
  5. *
  6. * @package chamilo.document
  7. *
  8. * @author Juan Carlos Raña Trabado
  9. * @since 5/mar/2011
  10. */
  11. /**
  12. * Code
  13. */
  14. require_once '../../../inc/global.inc.php';
  15. api_protect_course_script();
  16. api_block_anonymous_users();
  17. if (!isset($_GET['filename']) || !isset($_GET['filepath']) || !isset($_GET['dir']) || !isset($_GET['course_code']) || !isset($_GET['nano_group_id']) || !isset($_GET['nano_session_id']) || !isset($_GET['nano_user_id'])) {
  18. echo 'Error. Not allowed';
  19. exit;
  20. }
  21. if (!is_uploaded_file($_FILES['voicefile']['tmp_name'])) {
  22. exit;
  23. }
  24. //clean
  25. $nano_user_id = Security::remove_XSS($_GET['nano_user_id']);
  26. $nano_group_id = Security::remove_XSS($_GET['nano_group_id']);
  27. $nano_session_id = Security::remove_XSS($_GET['nano_session_id']);
  28. $filename = Security::remove_XSS($_GET['filename']);
  29. $filename = urldecode($filename);
  30. $filepath = Security::remove_XSS(urldecode($_GET['filepath']));
  31. $dir = Security::remove_XSS(urldecode($_GET['dir']));
  32. $course_code = Security::remove_XSS(urldecode($_GET['course_code']));
  33. $_course = api_get_course_info($course_code);
  34. $filename = trim($_GET['filename']);
  35. $filename = Security::remove_XSS($filename);
  36. $filename = Database::escape_string($filename);
  37. $filename = api_replace_dangerous_char($filename);
  38. $filename = disable_dangerous_file($filename);
  39. $title = trim(str_replace('_chnano_.', '.', $filename)); //hide nanogong wav tag at title
  40. $title = str_replace('_', ' ', $title);
  41. $documentPath = $filepath . $filename;
  42. if ($nano_user_id != api_get_user_id() || api_get_user_id() == 0 || $nano_user_id == 0) {
  43. echo 'Not allowed';
  44. exit;
  45. }
  46. // Do not use here check Fileinfo method because return: text/plain
  47. $groupInfo = GroupManager::get_group_properties($nano_group_id);
  48. if (!file_exists($documentPath)) {
  49. //add document to disk
  50. move_uploaded_file($_FILES['voicefile']['tmp_name'], $documentPath);
  51. //add document to database
  52. $current_session_id = $nano_session_id;
  53. $groupId = $nano_group_id;
  54. $file_size = filesize($documentPath);
  55. $relativeUrlPath = $dir;
  56. $doc_id = add_document($_course, $relativeUrlPath . $filename, 'file', filesize($documentPath), $title);
  57. api_item_property_update(
  58. $_course,
  59. TOOL_DOCUMENT,
  60. $doc_id,
  61. 'DocumentAdded',
  62. $nano_user_id,
  63. $groupInfo,
  64. null,
  65. null,
  66. null,
  67. $current_session_id
  68. );
  69. } else {
  70. return get_lang('FileExistRename');
  71. }