HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/xampp/htdocs/source/pbnTool/download.php
<?php
// Define the allowed files to prevent security issues (Directory Traversal)
$allowed_files = [
    'Mac-CT25-Pro1_2-M0.zip',
    'Mac-CT25_Pro3_M1.zip',
    'Win_CT25_Pro1_2-M0.zip',
    'Win_CT25_Pro3-M1.zip'
];
//
$file = $_GET['file'] ?? '';

if (in_array($file, $allowed_files) && file_exists($file)) {
    // 1. Log the download
    $statsFile = 'stats.json';
    $stats = file_exists($statsFile) ? json_decode(file_get_contents($statsFile), true) : [];
    
    $stats[$file] = ($stats[$file] ?? 0) + 1;
    file_put_contents($statsFile, json_encode($stats));

    // 2. Serve the file
    header('Content-Description: File Transfer');
    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
} else {
    die("File not found or access denied.");
}
?>