Home  >  Article  >  Backend Development  >  php-帮我看看下面的为啥不对,设置文件大小,当输入数据超过1M时就会覆盖前面的,显示最新1M的数据

php-帮我看看下面的为啥不对,设置文件大小,当输入数据超过1M时就会覆盖前面的,显示最新1M的数据

WBOY
WBOYOriginal
2016-06-02 11:32:09938browse

php

function writeLog($msg){
$max_size = 1000000;
$logFile = 'log.txt';
date_default_timezone_set('Asia/Chongqing');
$data = date('Y-m-d H:i:s').' >>> '.$msg."\r\n";
$size=filesize($logFile);
$temp=strlen($data);
if($size+$temp>$max_size){
$input=$data++;
$input = substr($input,(strlen($input)-$max_size));

}file_put_contents($logFile,$data,FILE_APPEND );

}
writeLog('hello');
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn