Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Use file_put_contents without removing the contents in it?

Comments in 'Plugin Development' started by CraftYourBukkit, May 22, 2015.

  1. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I want to put stuff into a file when typing a command but it always removes the content which is in it. How can I just leave the content there and put the new one in a new line?
  2. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    PHP:
    file_put_contents($file,file_get_contents($file) . $data);
    Or you can use fopen, fwrite, and fclose with the append flag.
    EvolSoft and CraftYourBukkit like this.
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Thanks!
    LDX likes this.
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    It is better to use
    PHP:
    file_put_contents($file$dataFILE_APPEND);
  5. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    I did not know that existed. :p

Share This Page

Advertisement