receiver.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  16. api_protect_course_script();
  17. api_block_anonymous_users();
  18. 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'])) {
  19. echo 'Error. Not allowed';
  20. exit;
  21. }
  22. if (!is_uploaded_file($_FILES['voicefile']['tmp_name'])) {
  23. exit;
  24. }
  25. //clean
  26. $nano_user_id = Security::remove_XSS($_GET['nano_user_id']);
  27. $nano_group_id = Security::remove_XSS($_GET['nano_group_id']);
  28. $nano_session_id = Security::remove_XSS($_GET['nano_session_id']);
  29. $filename = Security::remove_XSS($_GET['filename']);
  30. $filename = urldecode($filename);
  31. $filepath = Security::remove_XSS(urldecode($_GET['filepath']));
  32. $dir = Security::remove_XSS(urldecode($_GET['dir']));
  33. $course_code = Security::remove_XSS(urldecode($_GET['course_code']));
  34. $_course = api_get_course_info($course_code);
  35. $filename = trim($_GET['filename']);
  36. $filename = Security::remove_XSS($filename);
  37. $filename = Database::escape_string($filename);
  38. $filename = replace_dangerous_char($filename, $strict = 'loose'); // or strict
  39. $filename = disable_dangerous_file($filename);
  40. $title = trim(str_replace('_chnano_.', '.', $filename)); //hide nanogong wav tag at title
  41. $title = str_replace('_', ' ', $title);
  42. $documentPath = $filepath . $filename;
  43. if ($nano_user_id != api_get_user_id() || api_get_user_id() == 0 || $nano_user_id == 0) {
  44. echo 'Not allowed';
  45. exit;
  46. }
  47. // Do not use here check Fileinfo method because return: text/plain
  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. $groupId,
  64. null,
  65. null,
  66. null,
  67. $current_session_id
  68. );
  69. } else {
  70. return get_lang('FileExistRename');
  71. }