Browse Source

前端限制上传文件大小

UnknownO 3 years ago
parent
commit
cfd1edb8ae
2 changed files with 6 additions and 1 deletions
  1. 1 1
      config.php
  2. 5 0
      pages/submit.php

+ 1 - 1
config.php

@@ -21,7 +21,7 @@ $VERIFICATION_KEY = "KAGAMINE YES!";
 $UPLOAD_PATH = "../static/uploads/";
 //上传文件API接口(默认可以不用动
 $UPLOAD_API = "/api/upload.php";
-//最大上传文件大小
+//最大上传文件大小(KB)
 $MAX_UPLOAD_SIZE = 200;
 //是否允许上传文件(可能存在安全风险!
 $UPLOAD_IMAGE = true;

+ 5 - 0
pages/submit.php

@@ -73,7 +73,12 @@ if ($templateMode) {
         }
 
         $("#upload").on("change", "input[type='file']", function() {
+            max_size = <?php echo $MAX_UPLOAD_SIZE * 1024; ?>;
             file = $(this).prop('files')[0]
+            if (file.size > max_size) {
+                mdui.alert("上传失败!图片过大!本站允许上传的最大大小:" + (<?php echo $MAX_UPLOAD_SIZE; ?>).toString()+"KB")
+                return false
+            }
             imageVerification(function(answer) {
                 $('#upload-image').attr("disabled", "disabled")
                 $("#isLoading").show(100)