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

file_put_contents error

Comments in 'Plugin Development' started by Creeperface, Jun 25, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    my files in plugin resources folder:
    arenas/default.yml
    PHP:
    if(!is_file($this->getDataFolder()."arenas/default.yml")){
                    
    fopen($this->getDataFolder()."arenas/default.yml""w");
                    
    file_put_contents($this->getDataFolder()."arenas/default.yml"$this->getResource("arenas/default.yml"));
            }
    Code:
    [CRITICAL] Could not save Config C:\Users\Honza\Documents\PocketMine-MP\plugins\ColorMatch/arenas/C:\Users\Honza\Documents\PocketMine-MP\plugins\ColorMatch/arenas/default.yml: file_put_contents(C:\Users\Honza\Documents\PocketMine-MP\plugins\ColorMatch/arenas/C:\Users\Honza\Documents\PocketMine-MP\plugins\ColorMatch/arenas/default.yml): failed to open stream: Invalid argument
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,710
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Remove the everything in the if statement and replace it with
    PHP:
    $this->saveResource("arenas/default.yml");
    You may also need to create the "arenas" directory in your data folder, I am not sure.
    Creeperface likes this.
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    maybe problem was in this method:
    PHP:
    public function checkArenas(){
            
    $this->getLogger()->info("checking arena files...");
            foreach(
    glob($this->getDataFolder()."arenas/*.yml") as $file){
                
    $arena = new Config($fileConfig::YAML);
                if(
    $this->checkFile($arena)){
                    
    $last strrpos($file,'.')+1;
                    
    $pripona = ($last 1) ? substr($file$last) : false;
                    
    $this->setArenasData($arena$pripona);
                    
    $this->getLogger()->info("$file checking sucessful");
                }
                else{
                    
    $this->getLogger()->critical("$file is not setup properly");
                    return;
                }
            }
        }
    i used
    PHP:
    new Config($this->getDataFolder()."arenas/".$fileConfig::YAML);
    Last edited: Jun 25, 2015
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Try
    PHP:
    new Config($this->getDataFolder()."arenas/".$fileConfig::YAML);
    Creeperface likes this.
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    No it already works. I only forgot write "." here xD
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    That's what I posted xD
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is pointless to call fopen() if you don't use the return value as a stream to write/read to the file with.

Share This Page

Advertisement