From 3ca512908700d8d8385d2d5b4405839ef2532801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E9=97=BB=E9=A3=8E?= Date: Wed, 24 Jun 2026 18:34:15 +0800 Subject: [PATCH] up --- download.php | 60 +++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/download.php b/download.php index 586a499..8a24ba1 100644 --- a/download.php +++ b/download.php @@ -1,54 +1,46 @@ 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())); }