<?php
// 下载文件路径
$apk_path = __DIR__ . '/app/sky-official.apk';
$apk_name = 'sky_dianwanren.apk';

// 统计下载次数函数
function increment_download_count() {
    $count_file = __DIR__ . '/download_count.txt';
    if (!file_exists($count_file)) {
        file_put_contents($count_file, "0");
    }
    // 读+1+写
    $count = (int)file_get_contents($count_file);
    $count++;
    file_put_contents($count_file, (string)$count);
}

if (!file_exists($apk_path)) {
    http_response_code(404);
    echo '文件不存在';
    exit;
}

// 计数+1
increment_download_count();

// 输出下载文件头
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="' . $apk_name . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($apk_path));

// 读取文件内容
readfile($apk_path);
exit;
