up
This commit is contained in:
+26
-34
@@ -1,54 +1,46 @@
|
||||
<?php
|
||||
require_once 'includes/db.php';
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
try {
|
||||
$app = null;
|
||||
|
||||
if ($id) {
|
||||
// 按 ID 下载指定版本
|
||||
$stmt = $db->prepare("SELECT * FROM apps WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$app = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($app && file_exists('data/apps/' . $app['filename'])) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'file' => 'data/apps/' . rawurlencode($app['filename']),
|
||||
'filename' => $app['original_name'],
|
||||
'version' => $app['version'],
|
||||
'date' => date('Y-m-d H:i:s', strtotime($app['upload_time']))
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'APK 文件不存在'
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
// 兼容旧版:返回最新版本
|
||||
$stmt = $db->query("SELECT * FROM apps ORDER BY upload_time DESC LIMIT 1");
|
||||
$app = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
if ($app && file_exists('data/apps/' . $app['filename'])) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'file' => 'data/apps/' . rawurlencode($app['filename']),
|
||||
'filename' => $app['original_name'],
|
||||
'version' => $app['version'],
|
||||
'date' => date('Y-m-d H:i:s', strtotime($app['upload_time']))
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => '未找到 APK 文件'
|
||||
]);
|
||||
if ($app && file_exists('data/apps/' . $app['filename'])) {
|
||||
$file_path = 'data/apps/' . $app['filename'];
|
||||
$file_size = filesize($file_path);
|
||||
|
||||
// 设置下载响应头
|
||||
header('Content-Type: application/vnd.android.package-archive');
|
||||
header('Content-Disposition: attachment; filename="' . $app['original_name'] . '"');
|
||||
header('Content-Length: ' . $file_size);
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
|
||||
// 清空输出缓冲
|
||||
if (ob_get_level()) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
// 输出文件
|
||||
readfile($file_path);
|
||||
exit;
|
||||
} else {
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
die('错误:APK 文件不存在');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => '查询失败: ' . $e->getMessage()
|
||||
]);
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
die('错误:' . htmlspecialchars($e->getMessage()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user