Create a file with the name $pathname, and put into it the $contents
@param string $pathname filename
@param string $contents base64 encoded string
425850
public function createFile($pathname, $contents) {

        if (strpos($pathname, '/') !== false) {
            $dirName = dirname($pathname);
            $this->createDirectory($dirName);
        }
        file_put_contents($pathname, base64_decode($contents));
    }
882536
private function _writeToFile($filename, $contents)
    {
        // Check local tmp directory
        if (!is_dir($this->config['tmp']) || !is_writeable($this->config['tmp'])) {
            $this->fail('tmp directory not found or is not writable');
        }

        // Build temp file
        $tmp_file = $this->config['tmp'] . "/ftp_data_file.tmp";
        file_put_contents($tmp_file, $contents);

        // Update variables
        $this->filepath = $filename;
        $this->file = $contents;

        // Upload the file to server
        if ($this->isSFTP()) {
            $flag = defined('NET_SFTP_LOCAL_FILE') ? NET_SFTP_LOCAL_FILE : \phpseclib\Net\SFTP::SOURCE_LOCAL_FILE;

            $uploaded = @$this->ftp->put($filename, $tmp_file, $flag);
        } else {
            $uploaded = ftp_put($this->ftp, $filename, $tmp_file, FTP_BINARY);
        }
        if (!$uploaded) {
            $this->fail('failed to upload file to server');
        }
    }
1107598
static function write($filename, $contents, $overwriteExisting = true) {
        if (file_exists($filename) && self::isWritable($filename)) {
            if ($overwriteExisting) unlink($filename);
        }

        file_put_contents($filename, $contents);
    }
1361357
public function addFromString($localname , $contents)
    {
        return $this->pclZip->add(
            array(
                array(
                    PCLZIP_ATT_FILE_NAME    => $localname,
                    PCLZIP_ATT_FILE_CONTENT => $contents,
                )
            )
        );
    }
422299
public function load($pathname)
    {
        if (empty($pathname)) {
            throw new ConfigurationException('Configuration file pathname cannot be empty.');
        }

        $config = $this->getMergedConfig($pathname);

        return $this->processConfiguration($config, $pathname);
    }
890841
public function create_file_from_pathname($filerecord, $pathname) {
        global $DB;

        $filerecord = (array)$filerecord;  // Do not modify the submitted record, this cast unlinks objects.
        $filerecord = (object)$filerecord; // We support arrays too.

        // validate all parameters, we do not want any rubbish stored in database, right?
        if (!is_number($filerecord->contextid) or $filerecord->contextid < 1) {
            throw new file_exception('storedfileproblem', 'Invalid contextid');
        }

        $filerecord->component = clean_param($filerecord->component, PARAM_COMPONENT);
        if (empty($filerecord->component)) {
            throw new file_exception('storedfileproblem', 'Invalid component');
        }

        $filerecord->filearea = clean_param($filerecord->filearea, PARAM_AREA);
        if (empty($filerecord->filearea)) {
            throw new file_exception('storedfileproblem', 'Invalid filearea');
        }

        if (!is_number($filerecord->itemid) or $filerecord->itemid < 0) {
            throw new file_exception('storedfileproblem', 'Invalid itemid');
        }

        if (!empty($filerecord->sortorder)) {
            if (!is_number($filerecord->sortorder) or $filerecord->sortorder < 0) {
                $filerecord->sortorder = 0;
            }
        } else {
            $filerecord->sortorder = 0;
        }

        $filerecord->filepath = clean_param($filerecord->filepath, PARAM_PATH);
        if (strpos($filerecord->filepath, '/') !== 0 or strrpos($filerecord->filepath, '/') !== strlen($filerecord->filepath)-1) {
            // path must start and end with '/'
            throw new file_exception('storedfileproblem', 'Invalid file path');
        }

        $filerecord->filename = clean_param($filerecord->filename, PARAM_FILE);
        if ($filerecord->filename === '') {
            // filename must not be empty
            throw new file_exception('storedfileproblem', 'Invalid file name');
        }

        $now = time();
        if (isset($filerecord->timecreated)) {
            if (!is_number($filerecord->timecreated)) {
                throw new file_exception('storedfileproblem', 'Invalid file timecreated');
            }
            if ($filerecord->timecreated < 0) {
                //NOTE: unfortunately I make a mistake when creating the "files" table, we can not have negative numbers there, on the other hand no file should be older than 1970, right? (skodak)
                $filerecord->timecreated = 0;
            }
        } else {
            $filerecord->timecreated = $now;
        }

        if (isset($filerecord->timemodified)) {
            if (!is_number($filerecord->timemodified)) {
                throw new file_exception('storedfileproblem', 'Invalid file timemodified');
            }
            if ($filerecord->timemodified < 0) {
                //NOTE: unfortunately I make a mistake when creating the "files" table, we can not have negative numbers there, on the other hand no file should be older than 1970, right? (skodak)
                $filerecord->timemodified = 0;
            }
        } else {
            $filerecord->timemodified = $now;
        }

        $newrecord = new stdClass();

        $newrecord->contextid = $filerecord->contextid;
        $newrecord->component = $filerecord->component;
        $newrecord->filearea  = $filerecord->filearea;
        $newrecord->itemid    = $filerecord->itemid;
        $newrecord->filepath  = $filerecord->filepath;
        $newrecord->filename  = $filerecord->filename;

        $newrecord->timecreated  = $filerecord->timecreated;
        $newrecord->timemodified = $filerecord->timemodified;
        $newrecord->mimetype     = empty($filerecord->mimetype) ? $this->mimetype($pathname, $filerecord->filename) : $filerecord->mimetype;
        $newrecord->userid       = empty($filerecord->userid) ? null : $filerecord->userid;
        $newrecord->source       = empty($filerecord->source) ? null : $filerecord->source;
        $newrecord->author       = empty($filerecord->author) ? null : $filerecord->author;
        $newrecord->license      = empty($filerecord->license) ? null : $filerecord->license;
        $newrecord->status       = empty($filerecord->status) ? 0 : $filerecord->status;
        $newrecord->sortorder    = $filerecord->sortorder;

        list($newrecord->contenthash, $newrecord->filesize, $newfile) = $this->add_file_to_pool($pathname, null, $newrecord);

        $newrecord->pathnamehash = $this->get_pathname_hash($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename);

        try {
            $this->create_file($newrecord);
        } catch (dml_exception $e) {
            if ($newfile) {
                $this->filesystem->remove_file($newrecord->contenthash);
            }
            throw new stored_file_creation_exception($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid,
                                                    $newrecord->filepath, $newrecord->filename, $e->debuginfo);
        }

        $this->create_directory($newrecord->contextid, $newrecord->component, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->userid);

        return $this->get_file_instance($newrecord);
    }
723565
protected function write($contents, $assetFileName)
    {
        // Derive the filename that we will be writing to
        $directory = $this->getOutputDirectory($assetFileName);

        // Build the file name
        $filename = self::getOutputFileName($assetFileName);

        // The full file path
        $fullpath = $directory.$filename;

        // Make sure that the folder exists
        if(!file_exists($directory))
        {
            // It doesn't, so make it (allow us to write)
            mkdir($directory, 0777, true);
        }

        // Write the file to disk
        file_put_contents($fullpath, $contents);

        // Return the newly created file name
        return $fullpath;
    }
665856
public static function put($path, $contents, $lock = false)
    {
        return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
    }
263043
private static function createAndWriteFile(string $path, string $contents)
    {
        $fileHandle = fopen($path, 'wb');
        if ($fileHandle === false) {
            throw new \RuntimeException('The file "' . $path . '" could not be opened for writing.', 1519851153);
        }

        fwrite($fileHandle, $contents);
        fclose($fileHandle);
    }
407320
public function put($path, $contents)
    {
        $directory = dirname($path);
        $this->createDir($directory);
        $path = $this->getPath($path);
        if (!file_exists($path) && !is_writable(dirname($path))) {
            throw new RuntimeException(dirname($path) . ' is not writable');
        }

        if (file_exists($path) && !is_writable($path)) {
            throw new RuntimeException($path . ' is not writable');
        }

        return file_put_contents($path, $contents);
    }
1143288
public function write($path, $contents, Config $config)
    {
        return $this->update($path, $contents, $config);
    }
985578
public function write($path, $contents, array $config = []) {
        return $this->getFileSystem()->write($path, $contents, $config);
    }
1369547
protected function writeContentSafe($path, $content)
    {
        $count = 0;
        $tmpFile = tempnam(dirname($path), basename($path));

        if (@file_put_contents($tmpFile, $content) === false) {
            throw new SystemException(Lang::get('system::lang.file.create_fail', ['name'=>$tmpFile]));
        }

        while (!@rename($tmpFile, $path)) {
            usleep(rand(50000, 200000));

            if ($count++ > 10) {
                throw new SystemException(Lang::get('system::lang.file.create_fail', ['name'=>$path]));
            }
        }

        File::chmod($path);

        /*
         * Compile cached file into bytecode cache
         */
        if (Config::get('cms.forceBytecodeInvalidation', false)) {
            if (function_exists('opcache_invalidate') && ini_get('opcache.enable')) {
                opcache_invalidate($path, true);
            }
            elseif (function_exists('apc_compile_file')) {
                apc_compile_file($path);
            }
        }
    }
684455
public static function put(string $path, string $contents, bool $lock = false): int
    {
        return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
    }
816556
public function writeFile(
        string $content,
        string $filename,
        string $encoding = Encoder::DEFAULT_BYTE_MODE_ECODING,
        ?ErrorCorrectionLevel $ecLevel = null
    ) : void {
        file_put_contents($filename, $this->writeString($content, $encoding, $ecLevel));
    }
81123
public static function appendContents($filename, $contents)
    {
        $result = file_put_contents($filename, $contents, \LOCK_EX | \LOCK_NB | \FILE_APPEND);
        if ($result === false) {
            throw new \RuntimeException("Cannot append to the file: " . $filename);
        }
    }
636071
public function write($path, $contents, array $config = [])
    {
        return $this->fileSystem->write($path, $contents, $config);
    }