Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2004
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File writing problem

    I am having problems developing my chat program. What i want it to do is write to the begining of the file while trying to keep the rest. But so far it manages to delete the rest somehow. here is my code rightnow
    Code:
    <html>
    <head>
    </head>
    <body align='center'>
    <center>
    <iframe src='filer.php' width='95%' height='85%' name="as">
    </iframe>
    <br>
    <table width='95%'>
    <tr>
    <td align='center' width='100%'>
    <form action='chat.php' method='post' name='m'>
    Message : <input name='msg' size=60><input type='submit' name='send' value='Send'>
    <br>
    </form>
    </td>
    </tr>
    </table>
    </body>
    </html>
    <?php
    $name=$_COOKIE["name"];
    if(isset($_POST["msg"]))
    {
    $msg = $_POST["msg"];
    $file = "file.txt";
    $msg4 = $name . ":" . $msg . "\n";
    $msg3 = str_replace("<", " &lt; ", "$msg4");
    $msg2 = str_replace(">", " &gt; ", "$msg3");
    $fp = fopen ($file, 'r+');
    $contents = fread($fp, filesize($filename));
    fclose ($fp);
    $fp = fopen ($file, 'w+');
    fwrite ($fp, $msg2);
    fwrite ($fp, $contents);
    fclose ($fp);
    }
    Echo "Please Input a Message";
    ?>

  • #2
    Regular Coder
    Join Date
    Dec 2004
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this may be to late but forget what i just said i found a way to have the scroller go down to the very bottom. Sorry to any one who was working on this.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •