log_email("email to: " . $to . " at: " . $time);
}
function log_email($message){
$dir = dirname(__FILE__);
$filename = $dir . "/logs/email_log.txt";
echo $filename;
if(is_readable($filename)){
$handle = fopen($filename, "w+");
$contents = fread($handle, filesize($filename));
fwrite($handle, $message . "\n" . $contents);
fclose($handle);
}else{
echo 'The file is not readable.';
}
}
The file has 777 access, the file contains some text.
I get a warning up saying: Warning: fread(): Length parameter must be greater than 0 in …
$contents variable ends up containing nothing? Any ideas?
The directory must be correct because if i delete the file, my is_readable returns false.
You are truncating the file when you initially open it with this line.
So the size will be zero at that point triggering that warning.
You should probably do something like this: