I have some XML I've edited in ActionScript that I would like to save locally via php. My php script (called writeFile.php) is the following:
<?php
$variable = $_POST['data'];
$file = "tmp.xml";
$fh = fopen($file, 'w');
fwrite($fh, $variable);
fclose($fh);
echo "Done!";
?>
My ActionScript is the following:
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("writeFile.php");
var vars:URLVariables = new URLVariables();
vars.data = xml.toXMLString();
request.data = vars;
request.method = URLRequestMethod.POST;
loader.addEventListener(Event.COMPLETE,onComplete);
loader.load(request);
However, no file is being created, and thus obviously nothing is being written to it.
$_POST['data'](you've omitted it in your above example). Additionally, are you sure that the$_POSTvalue you are passing to your script has the key valuedata? Are the write permissions of the directory you are trying to write the file to777?vars.datawould create a data key value on the phpPOST.xml.toXMLString()is doing - where is that data coming from?xml.toXMLString()is (for all intents and purposes) just likexml.toString().xmlis an ActionScript object that contains XML data. So,xml.toString()is simply putting that data in a text format.Done? In your browser? Is your script making it that far?