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

Solved Question...

Comments in 'Plugin Development' started by HotFireyDeath, Apr 7, 2015.

  1. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    How would you be able to save an input given to a designated text file?
    You can use fwrite() to write the file/input but there is no way to save it. The input disappears after closing the server.
    By the way, the text file is located at "C:\Plugin\Plugin.txt".
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What? fwrite() saves the stream to the harddisk permanently. Unless you did something wrong that unlinked the file.
  3. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    It didn't. All of the input disappears after closing the plugin/server. It is a txt file. Anyways, it didn't appear to have been unlinked.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Can you show the code?
  5. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    EvolSoft, HotFireyDeath and luca28pet like this.
  7. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    I think you should inspect the documentation more carefully. Also, I am second PEMapModder suggestion of using file_xxx_contents.

    Anways, these are your issues:

    1. $file == true : the fopen function returns a resource or false. If you want to check if the file opened succesfully, you should test !== false.
    2. fopen($filename,"w") on enable will either create a new file, or truncate to zero any existing files. So in your test, filesize will always be zero.
    3. Yes, the fclose is important. As it is, you have memory leaks and because PHP is buffering writes, things may not be written properly.
    4. Your filenames are with backslashes and in quotes. Coming from Linux, that could be a problem, but can anybody else comment on that?
    HotFireyDeath likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Well in Linux you won't have C: :p

    Also, it is a better practice that you you escape backslashes as \\ rather than \, because if it is \n then it will become newline.
    luca28pet likes this.
  9. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    I had the "a" as a "w" but I thought changing it may help :p
  10. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    I was just saying that he forgot fclose() xD
    HotFireyDeath likes this.

Share This Page

Advertisement