我正在尝试在服务器上附加一个文本文件,并需要它来删除旧行并仅保留最新的 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);
?>