加入流量查看,访客与视频数量图片数量查看
This commit is contained in:
@@ -57,5 +57,23 @@ try {
|
||||
respond(false, '保存失败: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
respond(true, '保存成功', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
|
||||
$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) {}
|
||||
|
||||
respond(true, '保存成功', str_replace($_SERVER['DOCUMENT_ROOT'], '', $targetPath));
|
||||
|
||||
Reference in New Issue
Block a user