I Need to save xml from Flex to file on server with PHP, which PHP script?

北慕城南 提交于 2020-01-07 03:17:04

问题


I have a Flex app which is taking XML data and posting it to be saved to a file on the server, where it can be read later. Using tip found here on SO, I have the Flex part down (I think), but I am not a PHP programmer so I am unclear as to what should be in the PHP that handles the URLRequest:

protected function saveBtn_clickHandler(event:MouseEvent):void {
var saveData:XML = new XML();

saveData = myManager.exportFullXML();
trace(saveData);

var uploader:URLLoader = new URLLoader();
var data:URLVariables = new URLVariables();
data.xml = saveData.toXMLString();
trace(data.xml);
var req:URLRequest = new URLRequest("http://locahost/saveXML.php");
req.data = data;
uploader.load(req);

}


回答1:


First of all ensure that your request is a post one (it isn't mandatory, but it is a good practice as XMLs tend to be lengthy):

req.method = URLRequestMethod.POST;

The PHP part is simple as PI. You get the received data from the $_POST superglobal and you write it to your file with file_put_contents.

<?php
file_put_contents('path/to/file', $_POST['data']);
?>

Note: remember that anyone can post to that PHP file, so you need to implement some security mechanism to ensure you only save what your application sends.



来源:https://stackoverflow.com/questions/4377830/i-need-to-save-xml-from-flex-to-file-on-server-with-php-which-php-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!