PDA

View Full Version : PHP that writes XML anyone?


betamakz
10-12-2003, 11:28 PM
If I am sending XML to a PHP script, how do write that XML to an xml document on the server. I have sorted everything out in Flash, and all I really want to do is to write whatever XML that is being sent, which is controlled in falsh, to an XML file with a specified name.

I am a complete newbie when it comes to PHP, but this is what I've got so far based on various tutorials and stuff I found. So pardon my whatever:

<?php
$fp = fopen("filename.xml","w");
fwrite($fp,*****);
fclose($fp);
return(0);
?>

***** = what am I supposed to write here to reference what is being sent. It appears as if when you are sending XML it has no paramater name, as opposed to sending normal variables in MIME. So I don't know how to reference things. I might be completely off track here. Am I missing something really, painfully obvious? Like, is there some sort of XML specific PHP methods I should use, or that should be installed before it handles XML?

CyanBlue
10-13-2003, 12:38 AM
Howdy... ;)

So, basically you have contents of the XML file ready within the Flash and you just want to save it via PHP, right???

I don't know if there is any sort of thing you have to install beforehand or not, and I'd love hear more from others... ;)

I just made a quick sample with what you have described within my limited knowledge in PHP...fileXML = "writeXMLtest.xml";
theDoc = "<nav><subnav><item label=\"one\" url=\"demo1.swf\" /><item label=\"two\" url=\"demo2.swf\" /><item label=\"three\" url=\"demo3.swf\" /></subnav></nav>"

testLVs = new LoadVars();
testLVs.filename = fileXML;
testLVs.content = theDoc;
testLVs.sendAndLoad("http://localhost/test/betamakz/writeXML.php", testLVs, "POST");
testLVs.onLoad = function (success)
{
if (success)
trace("Success " + this.result);
else
trace("failure");
}<?php
$XMLFileName = $_POST['filename'];
$XMLContent = $_POST['content'];
@unlink($FileName);

$FilePointer = fopen ($XMLFileName, "w");

fwrite($FilePointer, $XMLContent);
fclose($FilePointer);

// There should be some error checking before you return the result...
echo ("result=Done");
?>

betamakz
10-13-2003, 01:36 AM
Thanks a lot CyanBlue.

That was useful, and through this post I found your 5000 list, which had the perfect thing I was looking for.

Great resource that. Thanks a lot.

CyanBlue
10-13-2003, 01:38 AM
You're welcome... ;)

If you found something useful, you might want to add it to this thread... That way, people who search the forum can have their answer as well... ;)

betamakz
10-13-2003, 02:21 AM
That is also a very goo idea:

In your list I found the following, posted by jimburton. So thanks jimburton:

===========================
jimburton wrote:

whichever language you use on the serverside, set the content type of the xml object before sending it:


ActionScript:
------------------------------------------------------------------------
my_xml = new XML("<tag1><tag2 /></tag1>");
my_xml.contentType = "text/xml";
my_xml.send("saveXML.php");
------------------------------------------------------------------------

then if you used php you would have a script like this in saveXML.php:

code:
------------------------------------------------------------------------
$fp=fopen("myxml.xml","wb");
fwrite($fp,$HTTP_RAW_POST_DATA);
fclose($fp);
echo "Done saving";
------------------------------------------------------------------------

though you may prefer to do it silently by using sendandload instead of send....you will need to have write access to the directory that you're creating the xml doc in. don't know the syntax for cf - it used to be harder to get the xml out of the form object in coldfusion (you had to serialize it into wddx b4 sending it) but now there is an cfxml object so I presume there's a better way - check that out if you're using cfmx.

CyanBlue
10-13-2003, 02:44 AM
Oh... That'll be this thread if somebody want to see the whole thread which I strongly advise you to... ;)
http://www.actionscript.org/forums/showthread.php3?s=&threadid=23419