buffer($contents); if (strpos($current_mime, 'image') === false) { echo "Invalid mime type file"; exit; } //path, file and title $paintFileName = $filename.'.'.$extension; $title = $title.'.'.$extension; $temp_file_2delete = Session::read('temp_realpath_image'); if (empty($temp_file_2delete)) { // Create file 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 $document = DocumentManager::addDocument( $courseInfo, $paintDir.$paintFileName, 'file', filesize($documentPath), $title ); if ($document) { Display::addFlash(Display::return_message(get_lang('Saved.'))); } } else { // Update $documentPath = $saveDir.'/'.$paintFileName; file_put_contents($documentPath, $contents); $paintFile = Session::read('paint_file'); //check path if (empty($paintFile)) { echo 'No attribute paint_file'; exit; } if ($paintFile == $paintFileName) { $documentId = DocumentManager::get_document_id($courseInfo, $paintDir.$paintFileName); update_existing_document($courseInfo, $documentId, filesize($documentPath), null); api_item_property_update( $courseInfo, TOOL_DOCUMENT, $documentId, 'DocumentUpdated', $_user['user_id'], $groupInfo, null, null, null, $sessionId ); } else { // add a new document $document = DocumentManager::addDocument( $courseInfo, $paintDir.$paintFileName, 'file', filesize($documentPath), $title ); if ($document) { Display::addFlash(Display::return_message(get_lang('Update successful'))); } } } if (!empty($temp_file_2delete)) { // Delete temporal file 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 ''; exit; } else { echo '