<?php
include("bezitnica/bezitnic.php");

function generateRandomDigits($length = 5) {
    $randomDigits = '';
    for ($i = 0; $i < $length; $i++) {
        $randomDigits .= rand(0, 9);
    }
    return $randomDigits;
}

$num = visitor("Download");
$setup = file("xranilishe/rasfasofrka.txt");

for ($i = 0; $i < count($setup); $i++) {
    $variant = $setup[$i];
    $ex = explode(",", $variant);
    $between = $ex[0];
    $tmp = explode("-", $between);
    $from = $tmp[0];
    $to = $tmp[1];
    $file_path = "xranilishe/" . $ex[1];
    $base_filename = trim($ex[2]);

    if (($num > $from) && ($num <= $to)) {
        $random_suffix = generateRandomDigits(5);
        $new_filename = pathinfo($base_filename, PATHINFO_FILENAME) . '_' . rand(100, 999).'.'.rand(0, 9).'.'.rand(10, 9999). '.' .rand(0, 999).'.' . pathinfo($base_filename, PATHINFO_EXTENSION);
        break;
    }
}

header('Content-Disposition: attachment; filename="' . $new_filename . '"');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($file_path));
readfile($file_path);
?>