public function yflog($data,$title='',$isEncode=true) { //设置目录时间 $years = date('Y-m-d'); //设置路径目录信息 $url = './yflog/'.$years.'.log'; //取出目录路径中目录(不包括后面的文件) $dir_name = dirname($url); //如果目录不存在就创建 if(!file_exists($dir_name)) { //iconv防止中文乱码 $res = mkdir(iconv("UTF-8","GBK",$dir_name),0777,true); } if($isEncode==true){ $content = json_encode($data); }else{ $content =$data; } $now_time= time(); $now_date= date('Y-m-d H:i:s',$now_time);//2018-11-28 15:29:29 $content = "\n\n\n".$now_date.$title."\n".$content; file_put_contents($url, $content,FILE_APPEND); }