karakash
asked on
Fatal error: Cannot redeclare file_put_contents()
Following function giving out error Fatal error: Cannot redeclare file_put_contents(). Can someone tell me what might be wrong with the statement? It was working fine in PHP4 but after upgrading server to php5 its giving the error.
function 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;
}
}
function 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;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or you can just use the core function instead since it does the same as your custom function.
file_put_contents($filenam e, $data, FILE_APPEND);
file_put_contents($filenam
ASKER
changing the function name giving the same error.
Check to see if your function is within a loop.
If it is, then take it out of the loop.
If it is, then take it out of the loop.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://us2.php.net/file_put_contents
You just need to rename your custom function to something different, then update the references to that function in your code.
You should have got the same Fatal error in php4, so this means the display_errors was off in your php.ini or this script.