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); $paintFile = Session::read('paint_file'); //check path if (empty($paintFile)) { api_not_allowed(); die(); } if ($paintFile == $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::read('temp_realpath_image'); unlink($temp_file_2delete); //Clean sessions and return to Chamilo file list Session::erase('paint_dir'); Session::erase('paint_file'); Session::erase('temp_realpath_image'); $exit = Session::read('exit_pixlr'); if (empty($exit)) { $location = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(); echo ''; api_not_allowed(true); } else { echo '
'.get_lang('PleaseStandBy').'
'; $location = api_get_path(WEB_CODE_PATH).'document/document.php?id='.Security::remove_XSS($exit).'&'.api_get_cidreq(); echo ''; Session::erase('exit_pixlr'); }