flex用php写服务器上的文本

时间:2013-09-16 19:03:56

标签: php flex append httpservice

我试图在服务器上附加一个文本文件,需要它删除旧行并保留最新的20个条目。每次尝试时,都会创建文本文件,但不会写入任何内容。谢谢!

MXML代码

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       height="900" width="800">


    <fx:Declarations>
        <mx:HTTPService id="userRequest" url="http://- my webserver -/history.php" useProxy="false" method="POST"/>
    </fx:Declarations>

    <fx:Script>
        <![CDATA[

            private function start():void{
                var history:String = history1.text;
                userRequest.send(history);
            }

        ]]>
    </fx:Script>
    <s:TextInput x="10" id="history1" text="text to send" bottom="10" enter="start()"/>
</s:WindowedApplication>

PHP代码

<?php


$stringToWrite = "".$_POST["history"]."";

$fh = fopen("test.txt", 'a');
fwrite($fh, $stringToWrite  );
fclose($fh);

$content=file($fh);

$file_content=array_slice($content,-20,20);
$file_content=implode("\n",$file_content);
file_put_contents($fh,$file_content);


?>

1 个答案:

答案 0 :(得分:0)

您正在调用文本输入“history1”,但在PHP代码中,您假设它被称为“历史记录”。 确保PHP REQUEST范围包含您认为具有的变量。 [更新,见评论]