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/track.php
<?php
// Set the timezone to Taiwan
date_default_timezone_set('Asia/Taipei');

$file = $_GET['file'] ?? '';
$logFile = 'download_log.csv';

// Secure the filename to prevent directory traversal
$file = basename($file); 

if (file_exists($file)) {
    // Save: Time (Taiwan), Filename, IP, and Referrer
    $data = [
        date('Y-m-d H:i:s'), 
        $file,
        $_SERVER['REMOTE_ADDR'],
        $_SERVER['HTTP_REFERER'] ?? 'Direct/Social'
    ];
    
    $f = fopen($logFile, 'a');
    fputcsv($f, $data);
    fclose($f);

    // Deliver the file
    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename="' . $file . '"');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
} else {
    header("HTTP/1.0 404 Not Found");
    echo "File not found.";
}
?>