S2OJ/web/app/controllers/image_hosting/get_image.php
Baoshuo e5ea7152a1
All checks were successful
continuous-integration/drone/push Build is passing
fix(web/image_hosting/get): return 403 instead of redirect to login
2022-10-18 10:55:24 +08:00

25 lines
578 B
PHP

<?php
requirePHPLib('form');
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
become403Page(UOJLocale::get('need login'));
}
$name = $_GET['image_name'];
if (!validateString($name)) {
become404Page();
}
$file_name = UOJContext::storagePath()."/image_hosting/$name.png";
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $file_name);
if ($mimetype === false) {
become404Page();
}
finfo_close($finfo);
header("X-Sendfile: $file_name");
header("Content-type: $mimetype");
header("Cache-Control: max-age=604800", true);