<?php
$servername = "localhost";
$username = "pail";
$password = "password";
$dbname = "download";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Vytvorenie tabulky "download", ak neexistuje
    $sql = "CREATE TABLE IF NOT EXISTS download (
                id INT AUTO_INCREMENT PRIMARY KEY,
                IP VARCHAR(45)
            )";
    $conn->exec($sql);

    // Záznam IP adresy užívatela do databázy
    $ip = $_SERVER['REMOTE_ADDR'];
    $sql = "INSERT INTO download (IP) VALUES (:ip)";
    $stmt = $conn->prepare($sql);
    $stmt->bindParam(':ip', $ip);
    $stmt->execute();

    // Stiahnutie súboru
    $file_path = '/var/www/html/skuska.exe'; // Upravte cestu k súboru podla potreby

    if (file_exists($file_path)) {
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
        header('Content-Length: ' . filesize($file_path));
        readfile($file_path);
        exit;
    } else {
        echo 'Súbor neexistuje.';
    }

} catch(PDOException $e) {
    echo "Chyba pri pripájaní k databáze: " . $e->getMessage();
}
?>






