mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-22 08:18:41 +00:00
fix(problem/manage/data): whitespace in dir name
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
25adb88dec
commit
e6e7e77e8e
@ -65,26 +65,41 @@ function echoFilePre($file_name) {
|
|||||||
if ($_POST['problem_data_file_submit'] == 'submit') {
|
if ($_POST['problem_data_file_submit'] == 'submit') {
|
||||||
if ($_FILES["problem_data_file"]["error"] > 0) {
|
if ($_FILES["problem_data_file"]["error"] > 0) {
|
||||||
$errmsg = "Error: " . $_FILES["problem_data_file"]["error"];
|
$errmsg = "Error: " . $_FILES["problem_data_file"]["error"];
|
||||||
becomeMsgPage('<div>' . $errmsg . '</div><a href="/problem/' . $problem['id'] . '/manage/data">返回</a>');
|
UOJResponse::message('<div>' . HTML::escape($errmsg) . '</div><a href="">返回</a>');
|
||||||
} else {
|
} else {
|
||||||
$zip_mime_types = array('application/zip', 'application/x-zip', 'application/x-zip-compressed');
|
$zip_mime_types = ['application/zip', 'application/x-zip', 'application/x-zip-compressed'];
|
||||||
|
|
||||||
if (in_array($_FILES["problem_data_file"]["type"], $zip_mime_types) || $_FILES["problem_data_file"]["type"] == 'application/octet-stream' && substr($_FILES["problem_data_file"]["name"], -4) == '.zip') {
|
if (in_array($_FILES["problem_data_file"]["type"], $zip_mime_types) || $_FILES["problem_data_file"]["type"] == 'application/octet-stream' && substr($_FILES["problem_data_file"]["name"], -4) == '.zip') {
|
||||||
$up_filename = "/tmp/" . rand(0, 100000000) . "data.zip";
|
|
||||||
move_uploaded_file($_FILES["problem_data_file"]["tmp_name"], $up_filename);
|
|
||||||
$zip = new ZipArchive;
|
$zip = new ZipArchive;
|
||||||
if ($zip->open($up_filename) === TRUE) {
|
|
||||||
$zip->extractTo("/var/uoj_data/upload/{$problem['id']}");
|
try {
|
||||||
$zip->close();
|
if ($zip->open($_FILES["problem_data_file"]["tmp_name"]) !== true) {
|
||||||
exec("cd /var/uoj_data/upload/{$problem['id']}; if [ -z \"`find . -maxdepth 1 -type f`\" ]; then for sub_dir in `find -maxdepth 1 -type d ! -name .`; do mv -f \$sub_dir/* . && rm -rf \$sub_dir; done; fi");
|
throw new UOJUploadFailedException('压缩文件打开失败');
|
||||||
echo "<script>alert('上传成功!')</script>";
|
|
||||||
} else {
|
|
||||||
$errmsg = "解压失败!";
|
|
||||||
becomeMsgPage('<div>' . $errmsg . '</div><a href="/problem/' . $problem['id'] . '/manage/data">返回</a>');
|
|
||||||
}
|
}
|
||||||
unlink($up_filename);
|
|
||||||
|
if (!$zip->extractTo(UOJProblem::cur()->getUploadFolderPath())) {
|
||||||
|
throw new UOJUploadFailedException('压缩文件解压失败');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$zip->close()) {
|
||||||
|
throw new UOJUploadFailedException('压缩文件关闭失败');
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
becomeMsgPage('<div>' . $e->getMessage() . '</div><a href="">返回</a>');
|
||||||
|
}
|
||||||
|
|
||||||
|
UOJLocalRun::execAnd([
|
||||||
|
['cd', UOJProblem::cur()->getUploadFolderPath()],
|
||||||
|
<<<'EOD'
|
||||||
|
if [ "$(find . -maxdepth 1 -type f)File" = "File" ];
|
||||||
|
then for sub_dir in "$(find -maxdepth 1 -type d ! -name .)";
|
||||||
|
do mv -f "$sub_dir"/* . && rm -rf "$sub_dir"; done; fi
|
||||||
|
EOD
|
||||||
|
]);
|
||||||
|
|
||||||
|
echo "<script>alert('上传成功!请点击「检验配置并同步数据」按钮同步数据。')</script>";
|
||||||
} else {
|
} else {
|
||||||
$errmsg = "请上传zip格式!";
|
becomeMsgPage('<div>请上传 zip 格式的文件!</div><a href="">返回</a>');
|
||||||
becomeMsgPage('<div>' . $errmsg . '</div><a href="/problem/' . $problem['id'] . '/manage/data">返回</a>');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user