CFile::setContents PHP Method

setContents() public method

This method works only for files.
public setContents ( string $contents = null, boolean $autocreate = True, integer $flags ) : CFile | boolean
$contents string Contents to be written
$autocreate boolean If 'True' file will be created automatically
$flags integer Flags for file_put_contents(). E.g.: FILE_APPEND to append data to file instead of overwriting.
return CFile | boolean Current CFile object on success, 'False' on fail.
    public function setContents($contents = null, $autocreate = True, $flags = 0)
    {
        if ($this->getIsFile()) {
            if ($autocreate && !$this->getExists()) {
                $this->create();
            }
            if ($this->getWriteable() && file_put_contents($this->_realpath, $contents, $flags) !== False) {
                return $this;
            }
            $this->addLog('Unable to put file contents');
            return False;
        } else {
            $this->addLog('setContents() method is available only for files', 'warning');
            return False;
        }
    }