init: 项目初始代码
This commit is contained in:
48
extend/utils/FileLog.php
Normal file
48
extend/utils/FileLog.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
class FileLog
|
||||
{
|
||||
private $filepath;
|
||||
|
||||
private $filename;
|
||||
|
||||
private $handle = null;
|
||||
|
||||
private $time;
|
||||
|
||||
public function __construct($filepath, $filename)
|
||||
{
|
||||
$this->time = date('Y-m-d H:i:s');
|
||||
$this->filepath = $filepath;
|
||||
$this->filename = $filename;
|
||||
$this->init();
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (!is_dir($this->filepath))
|
||||
{
|
||||
mkdir($this->filepath, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function write($content, $type='err')
|
||||
{
|
||||
$str = $type . '=====';
|
||||
$str .= '当前时间为: ' . $this->time;
|
||||
$str .= '=====';
|
||||
$str .= $content . PHP_EOL;
|
||||
|
||||
if (substr($this->filepath, -1) == '/')
|
||||
{
|
||||
$file = $this->filepath . $this->filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = $this->filepath . '/' . $this->filename;
|
||||
}
|
||||
|
||||
return file_put_contents($file, $str, FILE_APPEND);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user