I have a problem with my script where it displays all kinds of weird text when I need it to save. I got the script to work perfectly fine when there is no dynamic filename. However, when I ask the flash script to send a variable to the php file, it correctly writes the filename, but doesn't write the correct input text.

The below code is my comboBox code, which is used to select which file to edit:

var input_xml = new XML();
input_xml.ignoreWhite = true;
input_xml.contentType = "text/xml";
input_xml.onLoad = function(success) {
if (success) {
_root.editor.inputTxt.text = this.firstChild.firstChild.nodeValue;
_root.editor.displayTxt.text = "Load complete!";
} else {
_root.editor.inputTxt.text = "Error loading input XML";
}
};
comboform = new Object();
comboform.change = function(evtlist) {
_root.editor.fileTxt.text = comboBox.text;
_global.writefile = evtlist.target.value;
input_xml.load(_global.writefile+"?uniq="+new Date().getTime());
};
comboBox.addEventListener("change", comboform);


The below code is my main actionscript, which handles all of the loading and saving:

var input_xml = new XML();
input_xml.ignoreWhite = true;
input_xml.contentType = "text/xml";
input_xml.onLoad = function(success) {
if (success) {
inputTxt.text = this.firstChild.firstChild.nodeValue;
displayTxt.text = "Load complete!";
} else {
inputTxt.text = "Error loading input XML";
}
};
var output_xml = new XML();
output_xml.ignoreWhite = true;
output_xml.onLoad = function(success) {
if (success) {
output_txt.text = this.firstChild.firstChild.nodeValue;
displayTxt.text = "Save complete!";
} else {
output_txt.text = "Error loading output XML";
}
};
var server_file = "write.php";
sendBtn.onRelease = function() {
displayTxt.text = "Saving...";
writefile = _global.writefile;
loadVariablesNum("write.php", 0, "POST");
input_xml.parseXML("<edit> new text </edit>");
input_xml.firstChild.firstChild.nodeValue = inputTxt.text;
input_xml.xmlDecl = "";
input_xml.sendAndLoad(server_file, output_xml);
};


This last bit of code is my php script:
<?php
$filename = $_POST[writefile];
$raw_xml = file_get_contents("php://input");

print $raw_xml;

$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);
?>

If anyone can provide me with some insight on how to fix the code, I would be greatly appreciative of it.