PHP4 File Put Contents
Used in fooBar CMS – taken from the php.net web site in user contributed comments. This function is useful for people still running their websites on a php4 server as file_put_contents() is php5 only!Code:
if ( !function_exists(‘fb_file_put_contents’) && !defined(‘FILE_APPEND’) ) {
define(‘FILE_APPEND’, 1);
function fb_file_put_contents($n, $d, $flag = false) {
$mode = ($flag == FILE_APPEND || strtoupper($flag) == ‘FILE_APPEND’) ? ‘a’ : ‘w’;
$f = @fopen($n, $mode);
if ($f === false) {
return 0;
} else {
if (is_array($d)) $d = implode($d);
$bytes_written = fwrite($f, $d);
fclose($f);
return $bytes_written;
}
}
}