Calling file_put_contents within a destructor will cause the file to be written in SERVER_ROOT...
489737
public function save()
	{
		if (self::$file_added)
			file_put_contents($this->getFileListName(), '<?php return ' . var_export(self::$files[$this->prefix], true) . ';');

		self::$file_added = false;
	}
698456
function writeDataToFile (file, data, token) {
  // insertionPoint was set in hasInsertionPoint(), so we can assume it is safe to write to file
  var selectors = [
    'head > meta:last-of-type',
    'head > link:first-of-type',
    'head'
  ]
  var selectorIndex = 0

  switch (insertionPoint) {
    case 'meta':
      selectorIndex = 0
      break
    case 'link':
      selectorIndex = 1
      break
    case 'head':
      selectorIndex = 2
      break
    case 'token':
      let html = String(file.contents).replace(token, data)
      return new Buffer(html)
    default:
      return ''
  }

  var soup = new Soup(String(file.contents))

  // Inject Resource Hints
  soup.setInnerHTML(selectors[selectorIndex], function (oldHTML) {
    if (insertionPoint === 'link') {
      return data + oldHTML
    }
    return oldHTML + data
  })

  return soup.toString()
}
358989
def put_string(self, content, destination_s3_path, **kwargs):
        
        self._check_deprecated_argument(**kwargs)
        (bucket, key) = self._path_to_bucket_and_key(destination_s3_path)

        # put the file
        self.s3.meta.client.put_object(
            Key=key, Bucket=bucket, Body=content, **kwargs)
1250926
function(str) {
            var root, error = null;

            i = j = current = 0;
            chunks = [];
            input = str.replace(/\r\n/g, '\n');
            if (env.filename) {
                that.env.inputs[env.filename] = input;
            }

            // Split the input into chunks.
            chunks = (function (chunks) {
                var j = 0,
                    skip = /(?:@\{[\w-]+\}|[^"'`\{\}\/\(\)\\])+/g,
                    comment = /\/\*(?:[^*]|\*+[^\/*])*\*+\/|\/\/.*/g,
                    string = /"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'|`((?:[^`]|\\.)*)`/g,
                    level = 0,
                    match,
                    chunk = chunks[0],
                    inParam;

                for (var i = 0, c, cc; i < input.length;) {
                    skip.lastIndex = i;
                    match = skip.exec(input);
                    if (match) {
                        if (match.index === i) {
                            i += match[0].length;
                            chunk.push(match[0]);
                        }
                    }
                    c = input.charAt(i);
                    comment.lastIndex = string.lastIndex = i;

                    match = string.exec(input)
                    if (match) {
                        if (match.index === i) {
                            i += match[0].length;
                            chunk.push(match[0]);
                            continue;
                        }
                    }

                    if (!inParam && c === '/') {
                        cc = input.charAt(i + 1);
                        if (cc === '/' || cc === '*') {
                            match = comment.exec(input);
                            if (match) {
                                if (match.index === i) {
                                    i += match[0].length;
                                    chunk.push(match[0]);
                                    continue;
                                }
                            }
                        }
                    }

                    switch (c) {
                        case '{':
                            if (!inParam) {
                                level ++;
                            }
                            else {
                                inParam = false;
                            }
                            chunk.push(c);
                            break;
                        case '}':
                            if (!inParam) {
                                level --;
                                chunk.push(c);
                                chunks[++j] = chunk = [];
                            }
                            else {
                                inParam = false;
                                chunk.push(c);
                            }
                            break;
                        case '(':
                            if (!inParam) {
                                inParam = true;
                            }
                            else {
                                inParam = false;
                            }
                            chunk.push(c);
                            break;
                        case ')':
                            if (inParam) {
                                inParam = false;
                            }
                            chunk.push(c);
                            break;
                        default:
                            chunk.push(c);
                    }

                    i++;
                }
                if (level !== 0) {
                    error = {
                        index: i - 1,
                        message: (level > 0) ? "missing closing `}`" : "missing opening `{`",
                        filename: env.filename
                    };
                }

                return chunks.map(function (c) { return c.join(''); });
            })([[]]);

            if (error) {
                util.error(env, error);
                throw new Error('N/A');
            }

            // Start with the primary rule.
            // The whole syntax tree is held under a Ruleset node,
            // with the `root` property set to true, so no `{}` are
            // output.
            root = new tree.Ruleset([], $(this.parsers.primary));
            root.root = true;

            // Get an array of Ruleset objects, flattened
            // and sorted according to specificitySort
            root.toList = (function() {
                return function(env) {
                    env.frames = env.frames || [];


                    // call populates Invalid-caused errors
                    var definitions = this.flatten([], [], env);
                    definitions.sort(specificitySort);
                    return definitions;
                };
            })();

            // Sort rules by specificity: this function expects selectors to be
            // split already.
            //
            // Written to be used as a .sort(Function);
            // argument.
            //
            // [1, 0, 0, 467] > [0, 0, 1, 520]
            var specificitySort = function(a, b) {
                var as = a.specificity;
                var bs = b.specificity;

                if (as[0] != bs[0]) return bs[0] - as[0];
                if (as[1] != bs[1]) return bs[1] - as[1];
                if (as[2] != bs[2]) return bs[2] - as[2];
                return bs[3] - as[3];
            };

            return root;
        }
1082679
function append($path, $contents, $owner = null)
    {
        file_put_contents($path, $contents, FILE_APPEND);

        if ($owner) {
            $this->chown($path, $owner);
        }
    }
676101
function insertPastedContent(node, content, overwrite) {
		var nodesWithPlaceholders = node.findAll(function(item) {
			return hasOutputPlaceholder(item);
		});
		
		if (hasOutputPlaceholder(node))
			nodesWithPlaceholders.unshift(node);
		
		if (nodesWithPlaceholders.length) {
			nodesWithPlaceholders.forEach(function(item) {
				item.content = replaceOutputPlaceholders(item.content, content);
				item._attributes.forEach(function(attr) {
					attr.value = replaceOutputPlaceholders(attr.value, content);
				});
			});
		} else {
			// on output placeholders in subtree, insert content in the deepest
			// child node
			var deepest = node.deepestChild() || node;
			if (overwrite) {
				deepest.content = content;
			} else {
				deepest.content = abbrUtils.insertChildContent(deepest.content, content);
			}
		}
	}
849233
static function create_file($file_path_and_name, $file_content, $overwrite = false)
    {
        echo ("Setting up the file: ".$file_path_and_name.PHP_EOL);
        if (!$overwrite) {
            if (!file_exists($file_path_and_name)) {
                file_put_contents($file_path_and_name, $file_content);
            } else {
                self::error_out('Error: file already exists or cannot be written.');
            }
        } else {
            file_put_contents($file_path_and_name, $file_content);
        }
    }
139115
static void deleteDirContents(JobConf conf, File dir) throws IOException {
    FileSystem fs = FileSystem.getLocal(conf);
    if (fs.exists(new Path(dir.getAbsolutePath()))) {
      File contents[] = dir.listFiles();
      if (contents != null) {
        for (int i = 0; i < contents.length; i++) {
          if (!fs.delete(new Path(contents[i].getAbsolutePath()), true)) {
            LOG.warn("Unable to delete "+ contents[i]);
          }
        }
      }
    }
    else {
      LOG.warn(dir + " does not exist.");
    }
  }
1199283
function emit_destructor_code($out, PHP_ParserGenerator_Symbol $sp, &$lineno)
//    FILE *out;
//    struct symbol *sp;
//    struct lemon *lemp;
//    int *lineno;
    {
        $cp = 0;
        
        $linecnt = 0;
        if ($sp->type == PHP_ParserGenerator_Symbol::TERMINAL) {
            $cp = $this->tokendest;
            if ($cp === 0) {
                return;
            }
            $this->tplt_linedir($out, $this->tokendestln, $this->filename);
            fwrite($out, "{");
        } elseif ($sp->destructor) {
            $cp = $sp->destructor;
            $this->tplt_linedir($out, $sp->destructorln, $this->filename);
            fwrite($out, "{");
        } elseif ($this->vardest) {
            $cp = $this->vardest;
            if ($cp === 0) {
                return;
            }
            $this->tplt_linedir($out, $this->vardestln, $this->filename);
            fwrite($out, "{");
        } else {
            throw new Exception('emit_destructor'); /* Cannot happen */
        }
        for ($i = 0; $i < strlen($cp); $i++) {
            if ($cp[$i]=='$' && $cp[$i + 1]=='$' ) {
                fprintf($out, "(yypminor->yy%d)", $sp->dtnum);
                $i++;
                continue;
            }
            if ($cp[$i] == "\n") {
                $linecnt++;
            }
            fwrite($out, $cp[$i]);
        }
        $lineno += 3 + $linecnt;
        fwrite($out, "}\n");
        $this->tplt_linedir($out, $lineno, $this->outname);
    }
1288873
public void writeDirect ( byte[] b, int off, int len, int flags ) throws IOException {
        if ( len <= 0 ) {
            return;
        }

        if ( this.tmp == null ) {
            throw new IOException("Bad file descriptor");
        }

        try ( SmbFileHandleImpl fh = ensureOpen();
              SmbTreeHandleImpl th = fh.getTree() ) {
            if ( log.isDebugEnabled() ) {
                log.debug("write: fid=" + fh + ",off=" + off + ",len=" + len);
            }

            int w;
            do {
                int blockSize = ( this.file.getType() == SmbConstants.TYPE_FILESYSTEM ) ? this.writeSizeFile : this.writeSize;
                w = len > blockSize ? blockSize : len;

                if ( this.smb2 ) {
                    Smb2WriteRequest wr = new Smb2WriteRequest(th.getConfig(), fh.getFileId());
                    wr.setOffset(this.fp);
                    wr.setData(b, off, w);

                    Smb2WriteResponse resp = th.send(wr, RequestParam.NO_RETRY);
                    long cnt = resp.getCount();
                    this.fp += cnt;
                    len -= cnt;
                    off += cnt;
                }
                else if ( this.useNTSmbs ) {
                    this.reqx.setParam(fh.getFid(), this.fp, len - w, b, off, w);
                    if ( ( flags & 1 ) != 0 ) {
                        this.reqx.setParam(fh.getFid(), this.fp, len, b, off, w);
                        this.reqx.setWriteMode(0x8);
                    }
                    else {
                        this.reqx.setWriteMode(0);
                    }

                    th.send(this.reqx, this.rspx, RequestParam.NO_RETRY);
                    long cnt = this.rspx.getCount();
                    this.fp += cnt;
                    len -= cnt;
                    off += cnt;
                }
                else {
                    if ( log.isTraceEnabled() ) {
                        log.trace(String.format("Wrote at %d remain %d off %d len %d", this.fp, len - w, off, w));
                    }
                    this.req.setParam(fh.getFid(), this.fp, len - w, b, off, w);
                    th.send(this.req, this.rsp);
                    long cnt = this.rsp.getCount();
                    this.fp += cnt;
                    len -= cnt;
                    off += cnt;
                    if ( log.isTraceEnabled() ) {
                        log.trace(String.format("Wrote at %d remain %d off %d len %d", this.fp, len - w, off, w));
                    }
                }

            }
            while ( len > 0 );
        }
    }
206711
function (storeOrEditor, from, to) {
    debug('Performing inMemoryMove from ' + from + ' to ' + to);
    var store = (storeOrEditor && storeOrEditor.store ? storeOrEditor.store : storeOrEditor);
    var memFsEditor = require('mem-fs-editor').create(store);
    var fromLen = from.length;
    store.each(function (file) {
      var idx = file.path.indexOf(from);
      if (idx === 0 && file.contents !== null && file.state !== 'deleted') {
        var absTo = path.join(to, file.path.substr(fromLen));
        // exact match so we are copying a single file and not a folder
        if (fromLen === file.path.length) {
          absTo = path.join(to, path.basename(file.path));
        }
        debug('IN-MEMORY MOVING FROM: ' + file.path + ' TO: ' + absTo);
        memFsEditor.move(file.path, absTo);
      }
    });
  }
1273787
function (r) {
            // If DONE (cancelled), then don't do anything
            if (me.readyState === FileWriter.DONE) {
                return;
            }

            // position always increases by bytes written because file would be extended
            me.position += r;
            // The length of the file is now where we are done writing.

            me.length = me.position;

            // DONE state
            me.readyState = FileWriter.DONE;

            // If onwrite callback
            if (typeof me.onwrite === 'function') {
                me.onwrite(new ProgressEvent('write', { 'target':me }));
            }

            // If onwriteend callback
            if (typeof me.onwriteend === 'function') {
                me.onwriteend(new ProgressEvent('writeend', { 'target':me }));
            }
        }
311114
function(src, dest){
      self.logger.warn('File at '+dest+' exists, overwrite?');
      
      rl.question('(yN) ', function(answer){
        switch(answer.toLowerCase()){
          case 'y':
            this.copy(src, dest); 
            this.triggerNext(); 
            break; 
          case 'n':
            this.triggerNext(); 
            break; 
          default:
            this.waitForResponse(src, dest); 
            break; 
        }
      }.bind(this)); 
    }
146177
public void putContentStream(MIMETypedStream stream) throws StreamIOException {

        // TODO: refactor to use proper temp file management - FCREPO-718
        // for now, write to new temp file, clean up existing location
        String oldDSLocation = DSLocation;
        try {
            // note: don't use temp upload dir, use (container's) temp dir (upload dir is for uploads)
            File tempFile = File.createTempFile("managedcontentupdate", null);
            OutputStream os = new FileOutputStream(tempFile);
            StreamUtility.pipeStream(stream.getStream(), os, 32768);
            DSLocation = TEMP_SCHEME + tempFile.getAbsolutePath();
        } catch (Exception e) {
            throw new StreamIOException("Error creating new temp file for updated managed content (existing content is:" + oldDSLocation + ")", e);
        }

        // if old location was a temp location, clean it up
        // (if old location was uploaded, DefaultManagement should do this, but refactor up as part of FCREPO-718)
        if (oldDSLocation != null && oldDSLocation.startsWith(TEMP_SCHEME)) {
            File oldFile;
            try {
                oldFile = new File(oldDSLocation.substring(TEMP_SCHEME.length()));
            } catch (Exception e) {
                throw new StreamIOException("Error removing old temp file while updating managed content (location: " + oldDSLocation + ")", e);
            }
            if (oldFile.exists()) {
                if (!oldFile.delete()) {
                    logger.warn("Failed to delete temp file, marked for deletion when VM closes " + oldFile.getAbsolutePath());
                    oldFile.deleteOnExit();
                }
            } else
                logger.warn("Cannot delete temp file as it no longer exists " + oldFile.getAbsolutePath());
        }
    }
353959
def fs_write(file, contents)
      path = File.join(self.git_dir, file)
      FileUtils.mkdir_p(File.dirname(path))
      File.open(path, 'w') do |f|
        f.write(contents)
      end
    end
742607
public function close()
    {
        if (null !== $this->contents) {
            $result = file_put_contents($this->filename, json_encode($this->contents));
            if (false === $result) {
                throw new IOException('Unable to write to file!');
            }
            $this->contents = null;
        }
    }
1145373
def write_contents
        @contents.each do |relative_filepath, content|
          filepath = DM_STORAGE_PATH.join relative_filepath
          filedir  = filepath.dirname
          filedir.mkpath     unless (filedir.directory?)
          permission = 0644
          permission = 0600  if (filepath.basename.to_path == 'id_rsa')
          file = File.open filepath.to_path, ?w, permission
          file.write content
          file.close
        end
      end