0

サーバーにテキスト ファイルを追加しようとしていますが、古い行を削除して最新の 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);


?>
4

1 に答える 1

0

テキスト入力を「history1」と呼んでいますが、PHPコードでは「history」と呼ばれていると想定しています。PHP REQUEST スコープに、あると思われる変数があることを確認してください。[更新、コメントを参照]

于 2013-09-16T19:22:07.330 に答える