if($firstEntryStarts !== false) // if an existing entry is found, then insert the new one before it $xmlStr = substr($xmlStr, 0, $firstEntryStarts) . $insertXML . substr($xmlStr, $firstEntryStarts); else // otherwise - assume the new one will be the first entry $xmlStr = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . "<blog>\n{$insertXML}</blog>"; file_put_contents($fileName, $xmlStr); @chmod($fileName, 0666); } else { $xmlStr = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . "<blog>\n{$insertXML}</blog>"; file_put_contents($fileName, $xmlStr); @chmod($fileName, 0666); } $blog = BertaEditor::loadBlog($decoded['section']); BertaEditor::updateSectionEntryCount($decoded['section'], $blog); $returnUpdate['mediafolder'] = $mediafolder; $returnUpdate['entryid'] = $entryId; } } else { $returnError = 'cannot create media folder! check permissions.'; } } ?>