You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
<?php
|
|
|
|
$path = 'out';
|
|
$files = scandir($path);
|
|
$binaryFiles = [];
|
|
|
|
foreach($files as $file) {
|
|
if(str_ends_with($file, 'bin')) {
|
|
$binaryFiles[] = $file;
|
|
}
|
|
}
|
|
|
|
$current = date('i') % sizeof($binaryFiles);
|
|
|
|
$downloadName = $binaryFiles[$current];
|
|
$filePath = __DIR__ . '/out/' . $downloadName;
|
|
if (!is_file($filePath) || !is_readable($filePath)) {
|
|
http_response_code(404);
|
|
echo 'File not found.';
|
|
echo $filePath;
|
|
exit;
|
|
}
|
|
|
|
header('Content-Description: File Transfer');
|
|
header('Content-Type: application/octet-stream'); // generic binary MIME
|
|
header('Content-Disposition: attachment; filename="' . basename($downloadName) . '"');
|
|
header('Content-Transfer-Encoding: binary');
|
|
header('Expires: 0');
|
|
header('Cache-Control: must-revalidate, private');
|
|
header('Pragma: public');
|
|
|
|
header('Content-Length: ' . filesize($filePath));
|
|
|
|
while (ob_get_level()) {
|
|
ob_end_clean();
|
|
}
|
|
|
|
$chunkSize = 8192;
|
|
$handle = fopen($filePath, 'rb');
|
|
if ($handle === false) {
|
|
http_response_code(500);
|
|
echo 'Unable to open file.';
|
|
exit;
|
|
}
|
|
|
|
while (!feof($handle)) {
|
|
// Output a chunk and flush it immediately
|
|
echo fread($handle, $chunkSize);
|
|
flush(); // push to client
|
|
}
|
|
fclose($handle);
|
|
exit;
|
|
?>
|
|
|