File: C:/xampp/htdocs/source/pbnTool/dashboard.php
<?php
date_default_timezone_set('Asia/Taipei');
$logFile = 'download_log.csv';
$today = date('Y-m-d');
$counts = [];
$totalDownloads = 0;
$todayDownloads = 0;
$recentClicks = [];
if (file_exists($logFile)) {
if (($handle = fopen($logFile, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$time = $data[0];
$filename = $data[1];
// Count total
$counts[$filename] = ($counts[$filename] ?? 0) + 1;
$totalDownloads++;
// Count today's hits
if (strpos($time, $today) === 0) {
$todayDownloads++;
}
array_unshift($recentClicks, ["time" => $time, "file" => $filename]);
}
fclose($handle);
}
}
?>
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Download Dashboard (Taipei Time)</title>
<style>
body { font-family: -apple-system, sans-serif; background: #f0f2f5; padding: 15px; color: #1c1e21; }
.card { background: white; border-radius: 8px; padding: 15px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-bottom: 15px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 15px; }
.stat-box { background: #fff; padding: 15px; border-radius: 8px; text-align: center; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.stat-box span { display: block; font-size: 1.4rem; font-weight: bold; color: #1877f2; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 5px; border-bottom: 1px solid #ebedf0; }
.badge { background: #e7f3ff; color: #1877f2; padding: 3px 8px; border-radius: 5px; font-weight: 600; }
</style>
</head>
<body>
<h2 style="margin-bottom:5px;">PBN Tool Stats</h2>
<p style="font-size: 0.8rem; color: #65676b; margin-top:0;">Timezone: Asia/Taipei</p>
<div class="stat-grid">
<div class="stat-box"><span><?php echo $todayDownloads; ?></span> Today</div>
<div class="stat-box"><span><?php echo $totalDownloads; ?></span> Total</div>
</div>
<div class="card">
<strong>File Summary</strong>
<table>
<?php foreach($counts as $file => $count): ?>
<tr>
<td><?php echo htmlspecialchars($file); ?></td>
<td style="text-align:right;"><span class="badge"><?php echo $count; ?></span></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="card">
<strong>Last 5 Downloads</strong>
<ul style="list-style: none; padding: 0; font-size: 0.85rem; color: #444;">
<?php foreach(array_slice($recentClicks, 0, 5) as $click): ?>
<li style="margin-top: 10px; border-bottom: 1px solid #f0f2f5; padding-bottom: 5px;">
<span style="color:#65676b;"><?php echo $click['time']; ?></span><br>
<?php echo $click['file']; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
</body>
</html>