refactor: 使用FileManager统一文件操作
将分散在各处的文件操作统一封装到FileManager工具类中,包括文件读写、目录创建、JSON处理等操作
This commit is contained in:
19
admin.php
19
admin.php
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
// 基金监控系统管理页面
|
||||
require_once 'utils/FileManager.php';
|
||||
|
||||
// 启动会话
|
||||
session_start();
|
||||
@@ -35,18 +36,14 @@ if (isset($_GET['action']) && $_GET['action'] === 'logout') {
|
||||
|
||||
// 保存注销日志
|
||||
$log_file = 'data/operation_log.json';
|
||||
if (file_exists($log_file)) {
|
||||
$logs = json_decode(file_get_contents($log_file), true);
|
||||
if (!is_array($logs)) {
|
||||
$logs = [];
|
||||
}
|
||||
array_unshift($logs, $log_entry);
|
||||
// 限制日志数量
|
||||
if (count($logs) > 500) {
|
||||
$logs = array_slice($logs, 0, 500);
|
||||
}
|
||||
file_put_contents($log_file, json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||
FileManager::ensureDirExists(dirname($log_file));
|
||||
$logs = FileManager::loadJsonFile($log_file, []);
|
||||
array_unshift($logs, $log_entry);
|
||||
// 限制日志数量
|
||||
if (count($logs) > 500) {
|
||||
$logs = array_slice($logs, 0, 500);
|
||||
}
|
||||
FileManager::saveJsonFile($log_file, $logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
|
||||
// 销毁会话
|
||||
session_unset();
|
||||
|
||||
Reference in New Issue
Block a user