Write File in php

Discussion in 'PHP' started by pulikuttann, Mar 6, 2007.

  1. #1
    I am a newbie in php and I just entered the file writing.
    I have created a file and write to it from the browser with input text box.
    But when ever I write the older contents are rewritten.
    Can I make it static ???

    Help !!!
     
    pulikuttann, Mar 6, 2007 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    When you say:
    "But when ever I write the older contents are rewritten."

    do you mean:
    "But when ever I write the older contents are OVERwritten"?

    If so, you need to open the file in APPEND mode. Instead of opening it with the 'w' or 'w+' flag, try using 'a' or 'a+'.
     
    TwistMyArm, Mar 6, 2007 IP
  3. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    CodyRo, Mar 6, 2007 IP
  4. pulikuttann

    pulikuttann Banned

    Messages:
    1,839
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #4

    It was the problem and I fix it !!!
    Thankz for it !!!
     
    pulikuttann, Mar 6, 2007 IP
  5. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?php $fp = fopen("file.txt", "w+"); fwrite($fp, "Hello! "); fwrite($fp, "World!");?>
     
    jitesh, Mar 14, 2007 IP