receiver.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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, $strict = 'loose'); // or strict
  38. $filename = FileManager::disable_dangerous_file($filename);
  39. $title = trim(str_replace('_chnano_.', '.', $filename)); //hide nanogong wav tag at title
  40. $title = str_replace('_', ' ', $title);
  41. //
  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. // Check if there is enough space in the course to save the file
  49. if (!DocumentManager::enough_space(filesize($_FILES['voicefile']['tmp_name']), DocumentManager::get_course_quota())) {
  50. die(get_lang('UplNotEnoughSpace'));
  51. }
  52. if (!file_exists($documentPath)) {
  53. //add document to disk
  54. move_uploaded_file($_FILES['voicefile']['tmp_name'], $documentPath);
  55. //add document to database
  56. $current_session_id = $nano_session_id;
  57. $groupId = $nano_group_id;
  58. $file_size = filesize($documentPath);
  59. $relativeUrlPath = $dir;
  60. $doc_id = FileManager::add_document($_course, $relativeUrlPath.$filename, 'file', filesize($documentPath), $title);
  61. api_item_property_update(
  62. $_course,
  63. TOOL_DOCUMENT,
  64. $doc_id,
  65. 'DocumentAdded',
  66. $nano_user_id,
  67. $groupId,
  68. null,
  69. null,
  70. null,
  71. $current_session_id
  72. );
  73. } else {
  74. return get_lang('FileExistRename');
  75. }