streams/Code/Module/Ca.php

62 lines
1.4 KiB
PHP
Raw Normal View History

2020-03-05 04:07:26 +00:00
<?php
2021-12-03 03:01:39 +00:00
2021-12-02 22:33:36 +00:00
/**
*
*/
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2020-03-05 04:07:26 +00:00
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Storage\Stdio;
2020-03-05 04:07:26 +00:00
2021-12-02 22:33:36 +00:00
/**
* Ca
*/
class Ca extends Controller
{
2020-03-05 04:07:26 +00:00
2021-12-02 22:33:36 +00:00
/**
* get
*
* @return void
*/
2021-12-02 23:02:31 +00:00
public function get()
2021-12-02 22:33:36 +00:00
{
if (argc() > 1) {
$path = 'cache/img/' . substr(argv(1), 0, 2) . '/' . argv(1);
2020-03-05 04:07:26 +00:00
2021-12-02 22:33:36 +00:00
if (file_exists($path) && filesize($path)) {
$x = @getimagesize($path);
if ($x) {
header('Content-Type: ' . $x['mime']);
}
2021-12-02 22:33:36 +00:00
$cache = intval(get_config('system', 'photo_cache_time'));
2021-12-02 23:02:31 +00:00
if (!$cache) {
2021-12-02 22:33:36 +00:00
$cache = (3600 * 24); // 1 day
}
header(
'Expires: ' . gmdate('D, d M Y H:i:s', time() + $cache)
. ' GMT'
);
// Set browser cache age as $cache. But set timeout of
// 'shared caches' much lower in the event that infrastructure
// caching is present.
2021-12-02 23:02:31 +00:00
$smaxage = intval($cache / 12);
2021-12-02 22:33:36 +00:00
header(
'Cache-Control: s-maxage=' . $smaxage
. '; max-age=' . $cache . ';'
);
2021-04-06 02:23:04 +00:00
Stdio::fcopy($path,'php://output');
2021-12-02 22:33:36 +00:00
killme();
}
if ($_GET['url']) {
2022-08-14 09:20:43 +00:00
goaway($_GET['url']);
2021-12-02 22:33:36 +00:00
}
}
http_status_exit(404, 'Not found');
}
2021-12-03 03:01:39 +00:00
}