>\nendobj\n2 0 obj\n<< /Type /Pages /Kids [3 0 R] /Count 1 >>\nendobj\n3 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] >>\nendobj\nxref\n0 4\ntrailer\n<< /Size 4 /Root 1 0 R >>\nstartxref\n%%EOF");
file_put_contents($downloadsDir . '/项目源码.zip', "PK\x03\x04\n-- 模拟的ZIP文件内容 --\n此文件仅用于演示下载功能");
file_put_contents($downloadsDir . '/图片素材.png', base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='));
}
if (!is_file($statsFile)) {
file_put_contents($statsFile, json_encode([], JSON_PRETTY_PRINT));
}
// ============================================================
// 辅助函数
// ============================================================
function formatFileSize($bytes) {
if ($bytes >= 1073741824) return round($bytes / 1073741824, 2) . ' GB';
if ($bytes >= 1048576) return round($bytes / 1048576, 2) . ' MB';
if ($bytes >= 1024) return round($bytes / 1024, 2) . ' KB';
return $bytes . ' B';
}
function getFileIcon($filename) {
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$icons = [
'pdf' => '📕', 'doc' => '📘', 'docx' => '📘',
'xls' => '📗', 'xlsx' => '📗', 'ppt' => '📙',
'txt' => '📄', 'md' => '📄', 'csv' => '📊',
'zip' => '📦', 'rar' => '📦', '7z' => '📦', 'gz' => '📦',
'jpg' => '🖼️', 'jpeg' => '🖼️', 'png' => '🖼️', 'gif' => '🖼️', 'svg' => '🖼️',
'mp3' => '🎵', 'wav' => '🎵', 'flac' => '🎵',
'mp4' => '🎬', 'avi' => '🎬', 'mkv' => '🎬',
'php' => '💻', 'js' => '💻', 'html' => '💻', 'css' => '💻',
'exe' => '⚙️', 'dmg' => '⚙️', 'apk' => '📱',
];
return $icons[$ext] ?? '📁';
}
// ============================================================
// 处理文件下载请求
// ============================================================
if (isset($_GET['download'])) {
$requestedFile = basename($_GET['download']); // 安全过滤,防止路径穿越
$filePath = $downloadsDir . '/' . $requestedFile;
if (file_exists($filePath) && is_file($filePath)) {
// 更新下载统计
$stats = json_decode(file_get_contents($statsFile), true) ?: [];
$stats[$requestedFile] = ($stats[$requestedFile] ?? 0) + 1;
file_put_contents($statsFile, json_encode($stats, JSON_PRETTY_PRINT));
// 获取MIME类型
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, $filePath);
finfo_close($finfo);
if (!$mimeType) $mimeType = 'application/octet-stream';
$fileSize = filesize($filePath);
// 设置响应头并输出文件
header('Content-Type: ' . $mimeType);
header('Content-Disposition: attachment; filename="' . $requestedFile . '"');
header('Content-Length: ' . $fileSize);
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
ob_clean();
flush();
readfile($filePath);
exit;
} else {
// 文件不存在
header('HTTP/1.1 404 Not Found');
echo '
404文件不存在
您请求的文件未找到。
返回下载页面';
exit;
}
}
// ============================================================
// 确定当前页面
// ============================================================
$currentPage = $_GET['page'] ?? 'home';
$allowedPages = ['home', 'downloads'];
if (!in_array($currentPage, $allowedPages)) {
$currentPage = 'home';
}
// 获取下载统计
$stats = json_decode(file_get_contents($statsFile), true) ?: [];
// 获取下载文件列表
$downloadFiles = [];
if (is_dir($downloadsDir)) {
$files = scandir($downloadsDir);
foreach ($files as $file) {
if ($file === '.' || $file === '..' || $file === '.htaccess') continue;
$filePath = $downloadsDir . '/' . $file;
if (is_file($filePath)) {
$downloadFiles[] = [
'name' => $file,
'size' => filesize($filePath),
'modified' => filemtime($filePath),
'downloads'=> $stats[$file] ?? 0,
'icon' => getFileIcon($file),
];
}
}
// 按文件名排序
usort($downloadFiles, function($a, $b) {
return strcasecmp($a['name'], $b['name']);
});
}
?>
-
👋 欢迎来到
这里提供了丰富的资源文件供您下载。使用左侧导航栏可以快速切换到下载页面,浏览并获取您需要的文件。
🕐
$latestTime) $latestTime = $f['modified'];
}
echo $latestTime > 0 ? date('m/d', $latestTime) : '--';
?>
最近更新
📋 关于本站
这是一个简洁的资源下载站点。所有文件均通过左侧导航栏的「下载」页面进行管理和获取。
点击任意文件旁的下载按钮即可开始下载。系统会自动记录每个文件的下载次数,方便您了解热门资源。
如需添加更多文件,只需将文件放入服务器上的 downloads/ 目录即可自动出现在下载列表中。
0): ?>
💡
共 个文件可供下载。点击右侧按钮即可开始下载,所有文件均存储在服务器 downloads/ 目录中。
| 文件名称 |
大小 |
下载次数 |
更新日期 |
操作 |
|
|
|
次
|
|
⬇ 下载
|
📭
暂无文件可供下载
请将文件放入服务器上的 downloads/ 目录,它们将自动出现在这里。