11 Replies Latest reply on Oct 8, 2008 9:56 AM by kglad

    Delete .TXT File

    ThemeKings Level 1
      I'm creating a "Shoutbox" that saves all the user(s) post to a .txt file located in the main root directory. (named shout.txt) An example of the shoutbox can be seen http://www.342ft.com/home.htm

      My goal is to created a button, so that when users are done chatting, a button can be used to delete or whipout the shout.txt so that others can not see their conversations.

      Is there a script anyone is aware of that will allow me to create such a button, and if so, what that script may be?

      I'm using Flash 8
        • 1. Re: Delete .TXT File
          kglad Adobe Community Professional & MVP
          you'll need to use server-side scripting to delete the text file just like you need to use server-side scripting to write to a text file. shoutbox may provide that for you.
          • 2. Delete .TXT File
            ThemeKings Level 1
            I'm certain this can be done, so thats why I'm asking... lol

            Are you familiar with such a script? I use this script to post the message. Its attached to the "Send" button once someone types their message:



            on (release, keyPress "<Enter>") {
            loadVariablesNum("shout.php", 0, "POST");
            message = "";
            }


            The shout.php script reads like this:


            <?php
            extract($HTTP_GET_VARS);
            extract($HTTP_POST_VARS);
            header("Expires: ".gmdate("D, d M Y H:i:s")."GMT");
            header("Cache-Control: no-cache, must-revalidate");
            header("Pragma: no-cache");
            ?>
            <?php
            $nickname = str_replace ("\n"," ", $nickname);
            $nickname = str_replace ("<", " ", $nickname);
            $nickname = str_replace (">", " ", $nickname);
            $nickname = str_replace ("fk", "-", $nickname);
            $nickname = str_replace ("sk", "-", $nickname);
            $nickname = str_replace ("as", "-", $nickname);
            $nickname = str_replace ("&", "and", $nickname);
            $nickname = stripslashes ($nickname);
            $message = str_replace ("\n"," ", $message);
            $message = str_replace ("<", " ", $message);
            $message = str_replace ("&","and", $message);
            $message = str_replace ("fk", "-", $message);
            $message = str_replace ("sk", "-", $message);
            $message = str_replace ("a", "-", $message);
            $message = stripslashes ($message);
            $p=gmdate("d M H:i");
            ?>
            &output=
            <?php
            $chat_file = "shout.txt";
            $chat_lenght = 40;
            $max_single_msg_lenght = 100000;
            $max_file_size = $chat_lenght * $max_single_msg_lenght;
            $file_size= filesize($chat_file);
            if ($file_size > $max_file_size) {
            $lines = file($chat_file);
            $a = count($lines);
            $u = $a - $chat_lenght;
            for($i = $a; $i >= $u ;$i--){
            $msg_old = $lines[$i] . $msg_old;
            }
            $deleted = unlink($chat_file);
            $fp = fopen($chat_file, "a+");
            $fw = fwrite($fp, $msg_old);
            fclose($fp);
            }
            $msg = str_replace ("\n"," ", $message);
            $msg = stripslashes ($msg);
            if ($msg != ""){
            $fp = fopen($chat_file, "a+");
            $fw = fwrite($fp, "<font color=\"blue\"><b>$nickname:($p)<br></b></font> $msg\n");
            fclose($fp);}
            $lines = file($chat_file);
            $a = count($lines);
            $u = $a - $chat_lenght;
            for($i = $a; $i >= $u ;$i--){
            echo $lines[$i];
            }

            ?>
            • 3. Re: Delete .TXT File
              kglad Adobe Community Professional & MVP
              shout.php contains the server-side script that writes to your text file. you can create your own php file to delete the text file or check the docs to see if shoutbox already has done that for you.
              • 4. Delete .TXT File
                ThemeKings Level 1
                I have no documentation with the shoutbox. I created the shoutbox myself using tutorials and grabing bits and pieces of information, JUST LIKE NOW (hehe), to create this shoutbox.

                Dont get me wrong, the shoutbox works great, i just want to add another deminsion to it. Kinda like a chatbox. Any help would be greatly appreciated.

                I included the .php script above in a previous post

                Again, heres an example shoutbox. To see the send button you first have to enter a UN & PW to access or make post. Kinda kewl in itself.... hehe

                http://www.342ft.com/home.htm
                • 5. Re: Delete .TXT File
                  kglad Adobe Community Professional & MVP
                  the following php script will delete your file:

                  <?php
                  unlink("yourfile.txt");
                  ?>
                  • 6. Delete .TXT File
                    ThemeKings Level 1
                    It will clear the shout.txt file completely? (Thats what I want)

                    And what would the button actionscript read like? The button you press to clear the shout.txt that is.

                    If so, buddy I really appreciate the help!!!!
                    • 7. Re: Delete .TXT File
                      kglad Adobe Community Professional & MVP
                      yes, that will delete yourfile.txt.

                      you can use loadVariablesNum() like you're currently doing to call that php file, but it's better to use the loadvars class.
                      • 8. Re: Delete .TXT File
                        ThemeKings Level 1
                        Not working still.....

                        I created a php file called "delete.php" and it reads like this:

                        <?php
                        unlink("shout.txt");
                        ?>

                        Then the button I'm using on the ShoutBox to clear the text reads like this:

                        on (release, keyPress "<Enter>") {
                        loadVariablesNum("delete.php", 0, "GET");
                        }



                        Still does not clear the shout.txt file. Maybe its the wrong actionscript? Ya think?
                        • 9. Re: Delete .TXT File
                          ThemeKings Level 1
                          Wait, I got it to work:

                          I used POST instead of GET:

                          on (release, keyPress "<Enter>") {
                          loadVariablesNum("delete.php", 0, "POST");
                          }


                          It cleared the text!!!!
                          • 10. Re: Delete .TXT File
                            ThemeKings Level 1
                            Thanks for your patients bro! I appreciate your help!!!

                            Would you like for me to place a link to your site from mine?

                            www.themekings.com
                            • 11. Re: Delete .TXT File
                              kglad Adobe Community Professional & MVP
                              you're welcome.

                              and yes, thank you.