All pastes #96320 Raw Edit

Someone

public text v1 · immutable
#96320 ·published 2006-07-22 20:15 UTC
rendered paste body
<?php
if(!function_exists('file_put_contents')) {
	function file_put_contents($filename, $data, $append=false, $lock=false) {
		/* {{{ Puts $data into $filename */
		if(!is_readable($filename)) {
			return false;
		}
		if(empty($data)) { return false; }
		if($append) {
			$fp = @fopen($filename, 'a');
		} else {
			$fp = @fopen($filename, 'w');
		}
		if(!$fp) { return false; }

		if($lock) {
			if(!flock($fp, LOCK_EX)) {
				fclose($fp);
				return false;
			}
		}
		if(!fwrite($fp, $data)) {
			if($lock) { @flock($fp, LOCK_UN); }
			@fclose($fp);
			return false;
		}
		if($lock) {
			flock($fp, LOCK_UN);
		}

		fclose($fp);
		return true;
		/* }}} */
	}
}

file_put_contents('test.txt', 'hello!', true);