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. if (!file_exists($documentPath)) {
  48. //add document to disk
  49. move_uploaded_file($_FILES['voicefile']['tmp_name'], $documentPath);
  50. //add document to database
  51. $current_session_id = $nano_session_id;
  52. $groupId = $nano_group_id;
  53. $file_size = filesize($documentPath);
  54. $relativeUrlPath = $dir;
  55. $doc_id = add_document($_course, $relativeUrlPath . $filename, 'file', filesize($documentPath), $title);
  56. api_item_property_update(
  57. $_course,
  58. TOOL_DOCUMENT,
  59. $doc_id,
  60. 'DocumentAdded',
  61. $nano_user_id,
  62. $groupId,
  63. null,
  64. null,
  65. null,
  66. $current_session_id
  67. );
  68. } else {
  69. return get_lang('FileExistRename');
  70. }