<?php

$folder = __DIR__ . '/files';

// Auto-detect the only file
$files = array_values(array_filter(scandir($folder), function($f) use ($folder) {
    return !is_dir($folder . '/' . $f);
}));

if (count($files) !== 1) {
    die("Error: /files folder must contain exactly ONE file.");
}

$fileName = $files[0];
$filePath = $folder . '/' . $fileName;

// Force download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($fileName) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filePath));

flush();
readfile($filePath);
exit;
?>