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

fwrite() issue.

Comments in 'Plugin Development' started by HotFireyDeath, Jun 22, 2015.

Thread Status:
Not open for further replies.
  1. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    This happens in the section of code here:
    Code:
    $tag = $this->getConfig()->get("tag");
    $sender->sendMessage(TEXTFORMAT::RED."[".$tag."]"." PvP mode has been turned on!");
                
    $player = $sender->getName();
    $directori = file_get_contents($this->getDataFolder(). "/directory.txt");
    fwrite($directori, $player);
    fclose($directori);
    
    assume that the file_get_contents() directory was correct.


    This error pops up in console, pointing at the fwrite():
    Code:
    [CRITICAL] Unhandled exception executing command 'spvp on' in spvp: fwrite() expects parameter 1 to be resource, string given
    [WARNING] InvalidArgumentException: "fwrite() expects parameter 1 to be resource, string given" (E_WARNING) in "/SimplePvP-master/src/SimplePvP/SimplePvP" at line 29
    
    what is going wrong here?

    Also, using $sender raw instead of $player gives the same error.
  2. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    You have to use fwrite() with a resource.
    Try definying $directori like this:
    PHP:
    $directori fopen($path'w');
    fwrite($directori$player);
    //Then remember to
    fclose($directori);
    HotFireyDeath likes this.
  3. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Code:
    [CRITICAL] Unhandled exception executing command 'spvp on' in spvp: fopen(): Filename cannot be empty
    [WARNING] RuntimeException: "fopen(): Filename cannot be empty" (E_WARNING) in "/SimplePvP-master/src/SimplePvP/SimplePvP" at line 29
    
    $path variable was lead to the file directory using file_get_contents()

    that error will appear.
  4. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    No, forget my other post. My file directory isn't correct, sorry!
  5. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
Thread Status:
Not open for further replies.

Share This Page

Advertisement