fix(contest/resources): send file as attachment
All checks were successful
continuous-integration/drone Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2023-11-12 15:46:48 +08:00
parent b0368c76c4
commit b23313bd4f
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -19,12 +19,15 @@ $sub_path = UOJRequest::get('sub_path', 'is_string', '');
if ($sub_path) { if ($sub_path) {
$filepath = realpath(UOJContest::cur()->getResourcesPath(rawurldecode($sub_path))); $filepath = realpath(UOJContest::cur()->getResourcesPath(rawurldecode($sub_path)));
$realbasepath = realpath(UOJContest::cur()->getResourcesPath()); $realbasepath = realpath(UOJContest::cur()->getResourcesPath());
$filename = basename($filepath);
if (!strStartWith($filepath, $realbasepath)) { if (!strStartWith($filepath, $realbasepath)) {
UOJResponse::page406(); UOJResponse::page406();
} }
UOJResponse::xsendfile($filepath); UOJResponse::xsendfile($filepath, [
'attachment' => $filename,
]);
} }
$global_readonly = !UOJContest::cur()->userCanManage(Auth::user()); $global_readonly = !UOJContest::cur()->userCanManage(Auth::user());