0

I am trying to append a text file on the server and need it to delete the older line and keep only the latest 20 entries. Each time I try, the text files gets created but nothing gets written in it. Thanks !

MXML code

<?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 code

<?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 Answers1

0

You're calling your text input "history1" but in the PHP code you are assuming it is called "history". Make sure that the PHP REQUEST scope has the variables that you think it has. [UPDATED, SEE COMMENTS]

  • I see that now -- are you sure that it is passing it *as* history, and not just a string? Throw something like this after your first fopen to see what variables are actually in the scope: ob_start(); var_dump($_REQUEST); $stringToWrite = ob_get_clean(); – Daniel Ness Sep 17 '13 at 01:21