* @param $path string 日志文件目录
* @param $file string 日志文件名,不包含后缀
* @param $content string 记录内容
* @param @author yangzl
* @return void
**/
public function writeLogs($path,$file,$content,$more=true){
$newpath = '';
if (!file_exists($path)) {
mkdir ($path);
@chmod ($path, 0777 );
}
if($more){
$newpath .= $path.$file.@date('Y-m-d').".log";
}else{
$newpath .= $path.$file.".log";
}
$content .="\r\n"."----------------------------------------------------------------------------------------------------------------"."\r\n";
$this->write_file($newpath,$content,"a+");
}
/**
* 写内容
* @param $filename string 日志文件名
* @param $data string 记录内容
* @param $method
* @author yanzl
**/
private function write_file($filename,$data,$method="rb+",$iflock=1){
@touch($filename);
$handle=@fopen($filename,$method);
if($iflock){
@flock($handle,LOCK_EX);
}
@fputs($handle,$data);
if($method=="rb+") @ftruncate($handle,strlen($data));
@fclose($handle);
@chmod($filename,0777);
if( is_writable($filename) ){
return 1;
}else{
return 0;
}
}
}
?>
|