mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-12 01:50:48 +01:00
23163ae59c
scandir by default sorts files in ascending order. this is unnecessary when you're picking a random file anyway. it's just wasting CPU cycles and increasing latency as more files are added. currently it is $files = scandir($dir); it should be $files = scandir($dir, SCANDIR_SORT_NONE);
20 lines
551 B
PHP
20 lines
551 B
PHP
<?php
|
|
$dir = "static/banners/";
|
|
$files = scandir($dir, SCANDIR_SORT_NONE);
|
|
$images = array_diff($files, array('.', '..'));
|
|
$name = $images[array_rand($images)];
|
|
// open the file in a binary mode
|
|
$fp = fopen($dir . $name, 'rb');
|
|
|
|
// send the right headers
|
|
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1
|
|
header('Pragma: no-cache'); // HTTP 1.0
|
|
header('Expires: 0'); // Proxies
|
|
header('Content-Type: ' . $fp['type']);
|
|
header('Content-Length: ' . $fp['bytes']);
|
|
|
|
// dump the picture and stop the script
|
|
fpassthru($fp);
|
|
exit;
|
|
?>
|