0

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.

7
  • I'm assuming that in you PHP script you have a semi-colon after $_POST['data'] (you've omitted it in your above example). Additionally, are you sure that the $_POST value you are passing to your script has the key value data? Are the write permissions of the directory you are trying to write the file to 777? Commented Apr 6, 2011 at 16:56
  • This post seemed to indicate that using vars.data would create a data key value on the php POST. Commented Apr 6, 2011 at 17:02
  • What is it that xml.toXMLString() is doing - where is that data coming from? Commented Apr 6, 2011 at 17:16
  • xml.toXMLString() is (for all intents and purposes) just like xml.toString(). xml is an ActionScript object that contains XML data. So, xml.toString() is simply putting that data in a text format. Commented Apr 6, 2011 at 17:28
  • When you perform the above scripts, where do you see Done? In your browser? Is your script making it that far? Commented Apr 6, 2011 at 17:32

1 Answer 1

0

Make sure that you have write permission for that directory on the server. And in the onComplete function look for the server response to make sure you're seeing "Done!"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.