S2OJ/web/app/controllers/download.php

57 lines
1.4 KiB
PHP
Raw Normal View History

2016-07-18 16:39:37 +00:00
<?php
requirePHPLib('judger');
2022-03-17 04:00:03 +00:00
if (!Auth::check()) {
2022-04-02 10:01:26 +00:00
become403Page(UOJLocale::get('need login'));
2022-03-17 04:00:03 +00:00
}
2022-04-03 10:18:17 +00:00
if (!isNormalUser($myUser)) {
become403Page();
}
2016-07-18 16:39:37 +00:00
switch ($_GET['type']) {
case 'problem':
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page();
}
$visible = isProblemVisibleToUser($problem, $myUser);
if (!$visible && $myUser != null) {
$result = DB::query("select contest_id from contests_problems where problem_id = {$_GET['id']}");
while (list($contest_id) = DB::fetch($result, MYSQLI_NUM)) {
2016-07-18 16:39:37 +00:00
$contest = queryContest($contest_id);
genMoreContestInfo($contest);
if ($contest['cur_progress'] != CONTEST_NOT_STARTED && hasRegistered($myUser, $contest) && queryContestProblemRank($contest, $problem)) {
$visible = true;
}
}
}
if (!$visible) {
become404Page();
}
$id = $_GET['id'];
$file_name = "/var/uoj_data/$id/download.zip";
$download_name = "problem_$id.zip";
break;
case 'testlib.h':
$file_name = "/opt/uoj/judger/uoj_judger/include/testlib.h";
2016-07-18 16:39:37 +00:00
$download_name = "testlib.h";
break;
default:
become404Page();
}
$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("Content-Disposition: attachment; filename=$download_name");
2022-09-18 04:58:35 +00:00
?>