简体   繁体   English

我需要使用哪个PHP脚本将Flex中的xml保存到服务器上的文件中?

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

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. 我有一个Flex应用程序,该应用程序将XML数据发送并将其发布到服务器上的文件中,以供以后读取。 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: 使用在SO上找到的技巧,我可以将Flex部分放下(我认为),但是我不是PHP程序员,因此我不清楚在处理URLRequest的PHP中应该包含什么:

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);

} }

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): 首先,确保您的请求是发布请求(不是强制性的,但这是一个好习惯,因为XML往往很长):

req.method = URLRequestMethod.POST;

The PHP part is simple as PI. PHP部分像PI一样简单。 You get the received data from the $_POST superglobal and you write it to your file with file_put_contents . 您可以从$_POST超全局变量获取接收到的数据,并使用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. 注意:请记住,任何人都可以发布到该PHP文件,因此您需要实现某种安全机制,以确保仅保存应用程序发送的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM