Auth::id(), ], ]); $count = DB::selectCount([ "select count(*)", "from users_images", "where", [ "uploader" => Auth::id(), ], ]); function throwError($msg) { dieWithJsonData(['status' => 'error', 'message' => $msg]); } $allowedTypes = [IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_WEBP]; if ($_POST['image_upload_file_submit'] == 'submit') { if (!crsf_check()) { throwError('expired'); } if (!isset($_SESSION['phrase']) || !PhraseBuilder::comparePhrases($_SESSION['phrase'], $_POST['captcha'])) { unset($_SESSION['phrase']); throwError("bad_captcha"); } unset($_SESSION['phrase']); if ($_FILES["image_upload_file"]["error"] > 0) { throwError($_FILES["image_upload_file"]["error"]); } if ($_FILES["image_upload_file"]["size"] > 5242880) { // 5 MB throwError('too_large'); } if ($used + $_FILES["image_upload_file"]["size"] > $limit) { throwError('storage_limit_exceeded'); } $size = getimagesize($_FILES['image_upload_file']['tmp_name']); if (!$size || !in_array($size[2], $allowedTypes)) { throwError('not_a_image'); } list($width, $height, $type) = $size; $hash = hash_file("sha256", $_FILES['image_upload_file']['tmp_name']) . Auth::id(); $scale = ceil($width / 600.0); $watermark_text = UOJConfig::$data['profile']['oj-name-short']; if (isSuperUser(Auth::user()) && $_POST['watermark'] == 'no_watermark') { $watermark_text = ""; $hash .= "__no_watermark"; } elseif ($_POST['watermark'] == 'site_shortname_and_username') { $watermark_text .= ' @' . Auth::id(); $hash .= "__id"; } $existing_image = DB::selectFirst("SELECT * FROM users_images WHERE `hash` = '$hash'"); if ($existing_image) { dieWithJsonData(['status' => 'success', 'path' => $existing_image['path']]); } $image = new Imagick($_FILES["image_upload_file"]["tmp_name"]); $draw = new ImagickDraw(); $draw->setFont(UOJContext::documentRoot() . '/fonts/roboto-mono/RobotoMono-Bold.ttf'); $draw->setFontSize($scale * 14); $draw->setGravity(Imagick::GRAVITY_SOUTHEAST); $draw->setFillColor("rgba(100,100,100,0.5)"); $image->annotateImage($draw, 15, 10, 0, $watermark_text); $draw->setFillColor("rgba(255,255,255,0.65)"); $image->annotateImage($draw, 15 + $scale, 10 + $scale, 0, $watermark_text); $image->setImageFormat('png'); $image->writeImage(); if (($size = filesize($_FILES["image_upload_file"]["tmp_name"])) > 5242880) { // 5 MB throwError('too_large'); } $filename = uojRandAvaiableFileName('/image_hosting/', 10, '.png'); if (!move_uploaded_file($_FILES["image_upload_file"]["tmp_name"], UOJContext::storagePath() . $filename)) { throwError('unknown error'); } DB::insert([ "insert into users_images", DB::bracketed_fields(["path", "uploader", "width", "height", "upload_time", "size", "hash"]), "values", DB::tuple([ $filename, Auth::id(), $width, $height, DB::now(), $_FILES["image_upload_file"]["size"], $hash, ]), ]); dieWithJsonData(['status' => 'success', 'path' => $filename]); } elseif ($_POST['image_delete_submit'] == 'submit') { crsf_defend(); $id = $_POST['image_delete_id']; if (!validateUInt($id)) { becomeMsgPage('ID 不合法。返回'); } else { $result = DB::selectFirst("SELECT * from users_images WHERE id = $id"); if (!$result) { becomeMsgPage('图片不存在。返回'); } else { unlink(UOJContext::storagePath() . $result['path']); DB::delete("DELETE FROM users_images WHERE id = $id"); header("Location: " . UOJContext::requestURI()); die(); } } } ?>

点击此处选择图片

水印

上传须知

  • 上传的图片必须符合法律与社会道德;
  • 图床仅供 S2OJ 站内使用,校外用户无法查看;
  • 图片上传后会被自动转码为 PNG 格式;
  • 在合适的地方插入图片即可引用。

更多信息可以查看 使用文档

使用统计

已用空间 MB / MB
上传总数
20, 'col_names' => ['*'], 'table_name' => 'users_images', 'cond' => "uploader = '{$myUser['username']}'", 'tail' => 'order by upload_time desc', ]; $pag = new Paginator($pag_config); ?>

我的图片

get() as $idx => $row) : ?>
isEmpty()) : ?>
pagination() ?>