**写入日志**
~~~
public function write($file, $data, $pre = false)
{
if (empty($data)) {
$data = '空值传入!';
}
if (is_array($data)) {
if ($pre) {
$data = var_export($data, true);
} else {
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
}
}
$reletive_dir = preg_replace('/(.*)\/{1}(.*)/i', '$1,$2', $file);
$reletive_dir = explode(',', $reletive_dir);
if (!empty($reletive_dir[1])) {
self::_mkdirs(ROOT_PATH . '/log/' . $reletive_dir[0]);
}
file_put_contents(ROOT_PATH . '/log/' . $file . date('Ymd') . '.txt', $data . PHP_EOL, FILE_APPEND);
}
~~~
## 删除指定文件夹下所有内容
```
function delete_folder($folder_path) {
if (is_dir($folder_path)) {
$files = scandir($folder_path);
foreach ($files as $file) {
if ($file != "." && $file != "..") {
if (is_dir("$folder_path/$file")) {
delete_folder("$folder_path/$file");
} else {
unlink("$folder_path/$file");
}
}
}
rmdir($folder_path);
}
}
```