加入流量查看,访客与视频数量图片数量查看
This commit is contained in:
@@ -77,6 +77,25 @@ if ($skipDownload) {
|
||||
}
|
||||
}
|
||||
|
||||
$bytes = @filesize($targetPath) ?: 0;
|
||||
try {
|
||||
$statsRoot = __DIR__ . '/../stats';
|
||||
if (!is_dir($statsRoot)) { @mkdir($statsRoot, 0777, true); }
|
||||
$dailyPath = $statsRoot . '/daily.json';
|
||||
$today = (new DateTime('now'))->format('Y-m-d');
|
||||
$daily = [];
|
||||
if (file_exists($dailyPath)) {
|
||||
$rawDaily = @file_get_contents($dailyPath);
|
||||
$decoded = json_decode($rawDaily, true);
|
||||
if (is_array($decoded)) { $daily = $decoded; }
|
||||
}
|
||||
if (!isset($daily[$today]) || !is_array($daily[$today])) {
|
||||
$daily[$today] = ['visits' => 0, 'video_plays' => 0, 'picture_shows' => 0, 'uv' => 0, 'bandwidth_in' => 0, 'bandwidth_out' => 0];
|
||||
}
|
||||
$daily[$today]['bandwidth_out'] += (int)$bytes;
|
||||
@file_put_contents($dailyPath, json_encode($daily, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOCK_EX);
|
||||
} catch (Throwable $e) {}
|
||||
|
||||
// 恢复清理逻辑:仅保留最近两天的视频目录,删除更早的目录
|
||||
try {
|
||||
$dirs = @scandir($videosRoot);
|
||||
@@ -93,7 +112,7 @@ try {
|
||||
// 按日期升序排序
|
||||
sort($dateDirs);
|
||||
// 保留最近两天(末尾两项),其它全部删除
|
||||
if (count($dateDirs) > 30) {
|
||||
if (count($dateDirs) > 2) {
|
||||
$toDelete = array_slice($dateDirs, 0, count($dateDirs) - 2);
|
||||
foreach ($toDelete as $del) {
|
||||
rrmdir($videosRoot . DIRECTORY_SEPARATOR . $del);
|
||||
|
||||
Reference in New Issue
Block a user