buffer($contents); if (strpos($current_mime, 'image') === false) { echo "Invalid mime type file"; exit; } //path, file and title $paintFileName = $filename.'.'.$extension; $title = $title.'.'.$extension; if ($currentTool == 'document/createpaint') { //check save as and prevent rewrite an older file with same name if (0 != $groupId) { $group_properties = GroupManager :: get_group_properties($groupId); $groupPath = $group_properties['directory']; } else { $groupPath = ''; } if (file_exists($saveDir.'/'.$filename.'.'.$extension)) { $i = 1; while (file_exists($saveDir.'/'.$filename.'_'.$i.'.'.$extension)) $i++; $paintFileName = $filename.'_'.$i.'.'.$extension; $title = $filename.'_'.$i.'.'.$extension; } // $documentPath = $saveDir.'/'.$paintFileName; //add new document to disk file_put_contents($documentPath, $contents); //add document to database $doc_id = add_document($_course, $relativeUrlPath.'/'.$paintFileName, 'file', filesize($documentPath), $title); api_item_property_update( $_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupInfo, null, null, null, $current_session_id ); } elseif ($currentTool == 'document/editpaint') { $documentPath = $saveDir.'/'.$paintFileName; //add new document to disk file_put_contents($documentPath, $contents); //check path if (!isset($_SESSION['paint_file'])) { api_not_allowed(); die(); } if ($_SESSION['paint_file'] == $paintFileName) { $document_id = DocumentManager::get_document_id($_course, $relativeUrlPath.'/'.$paintFileName); update_existing_document($_course, $document_id, filesize($documentPath), null); api_item_property_update( $_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $_user['user_id'], $groupInfo, null, null, null, $current_session_id ); } else { //add a new document $doc_id = add_document( $_course, $relativeUrlPath.'/'.$paintFileName, 'file', filesize($documentPath), $title ); api_item_property_update( $_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupInfo, null, null, null, $current_session_id ); } } //delete temporal file $temp_file_2delete = $_SESSION['temp_realpath_image']; unlink($temp_file_2delete); //Clean sessions and return to Chamilo file list unset($_SESSION['paint_dir']); unset($_SESSION['paint_file']); unset($_SESSION['whereami']); unset($_SESSION['temp_realpath_image']); if (!isset($_SESSION['exit_pixlr'])) { $location = api_get_path(WEB_CODE_PATH).'document/document.php'; echo ''; api_not_allowed(true); } else { echo '
'.get_lang('PleaseStandBy').'
'; $location = api_get_path(WEB_CODE_PATH).'document/document.php?id='.Security::remove_XSS($_SESSION['exit_pixlr']); echo ''; unset($_SESSION['exit_pixlr']); }