I've already saw this question but it didn't help me.
How do I prepend file to beginning??
I've this script that appends a message to the end of a file:
if ( ! $fp = @fopen($filepath, 'ab'))
{
return FALSE;
}
$message .= $level.' - '.date($this->_date_fmt).' --> '.print_r($msg, TRUE)."\n";
if($this->_add_location){
foreach (array_reverse(debug_backtrace()) as $key => $step) {
$message .= ' # '.($key+1).' Line: '.$step['line'].' File: '.$step['file'];
if(isset($step['function']) && $step['function']==$this->_func_call) $message .= " ---> Call\n";
else $message .= "\n";
}
$message .= "\n";
}
flock($fp, LOCK_EX);
for ($written = 0, $length = strlen($message); $written < $length; $written += $result)
{
if (($result = fwrite($fp, substr($message, $written))) === FALSE)
{
break;
}
}
flock($fp, LOCK_UN);
fclose($fp);
What I want to know is if there is a way of prepending information by just changing the writing mode ab
to other value or do I have to rewrite the entire script to do that?