加入流量查看,访客与视频数量图片数量查看

This commit is contained in:
LL
2025-11-18 15:10:00 +08:00
parent 3c348195b7
commit 558188765e
9 changed files with 257 additions and 3 deletions

View File

@@ -71,6 +71,25 @@ if (!move_uploaded_file($file['tmp_name'], $target)) {
exit;
}
$bytes = (int)($file['size'] ?? 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_in'] += (int)$bytes;
@file_put_contents($dailyPath, json_encode($daily, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOCK_EX);
} catch (Throwable $e) {}
$meta = [
'original_name' => $origName,
'saved_name' => basename($target),