Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with AS3 + PHP?

Status
Not open for further replies.

MysticDrow

Technical User
Sep 5, 2008
1
PL
Hi. I have been fighting the last few days with php to make it create an xml file. Actually it DOES create it but I'm not able to choose the name of the file from my AS3 code. Here is the AS3:

Code:
var myXMLText:String = "<?xml version='1.0' encoding='ISO-8859-1'?><contents><name>mapa.xml</name><mapa>hereGoesTheRealText</mapa></contents>";
	
var mapaXML:XML = new XML(myXMLText);
var urlRequest:URLRequest = new URLRequest("save.php");
urlRequest.data = mapaXML;
urlRequest.contentType = "text/xml";
urlRequest.method = URLRequestMethod.POST;
	
var xmlSend:URLLoader = new URLLoader();
xmlSend.addEventListener(Event.COMPLETE, loaded);
xmlSend.load(urlRequest);

and here goes the php:

Code:
<?php 
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){ 
    $xml = $GLOBALS["HTTP_RAW_POST_DATA"]; 
    $name = $xml->name;
    $file = fopen($name,"wb"); 
    fwrite($file, $xml); 
    fclose($file); 

    echo($GLOBALS["HTTP_RAW_POST_DATA"]); 
} 
?>

The code does NOTHING, but if I replace the line

$name = $xml->name;

with this one:

$name = "someMap.xml";

everything works perfectly and it creates a document named "someMap.xml". So the problem is the php file cannot read the xml format using just the simplexml "->" or it doesn't "know" i'ts simplexml. I also tried

$_xml = $GLOBALS["HTTP_RAW_POST_DATA"];
$xml = new SimpleXMLElement($_xml);

and even opening the "someMap.xml" file once it's created to get the name info but with no effect :/ Anyone could help me? Why doesn't it work and how can I fix it?
Thanks
Mystic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top