forked from GithubBackups/vichan
Merge pull request #725 from Zankaria/banners-redirect
Make banner access redirect instead of serving the image directly
This commit is contained in:
commit
73a83e5dc9
22
b.php
22
b.php
@ -1,20 +1,8 @@
|
|||||||
<?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
|
$files = scandir('static/banners/', SCANDIR_SORT_NONE);
|
||||||
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1
|
$files = array_diff($files, ['.', '..']);
|
||||||
header('Pragma: no-cache'); // HTTP 1.0
|
|
||||||
header('Expires: 0'); // Proxies
|
|
||||||
$fstat = fstat($fp);
|
|
||||||
header('Content-Type: ' . mime_content_type($dir . $name));
|
|
||||||
header('Content-Length: ' . $fstat['size']);
|
|
||||||
|
|
||||||
// dump the picture and stop the script
|
$name = $files[array_rand($files)];
|
||||||
fpassthru($fp);
|
header("Location: /static/banners/$name", true, 307);
|
||||||
exit;
|
header('Cache-Control: no-cache');
|
||||||
?>
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user