From 24b9589416164d044a5dd950acefc5accfc2cb58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E6=8E=8C?= Date: Wed, 13 Jul 2022 16:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8A=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=A0=BC=E5=BC=8F=E9=AA=8C=E8=AF=81=EF=BC=8C=E6=84=9F?= =?UTF-8?q?=E8=B0=A2=E7=BE=A4=E5=8F=8B=E5=86=B7=E9=A3=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/student/model/Student.php | 2 ++ app/tools/controller/File.php | 11 ++++++++++- app/tools/validate/File.php | 29 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 app/tools/validate/File.php diff --git a/app/student/model/Student.php b/app/student/model/Student.php index 46067dc5..237e662c 100755 --- a/app/student/model/Student.php +++ b/app/student/model/Student.php @@ -130,6 +130,8 @@ class Student extends BaseModel $src = array_cover($srcfrom, $src); $src['banji_id'] = str_to_array($src['banji_id']); + halt($src); + $njlist = \app\facade\Tools::nianJiNameList(time(), 'num'); $zxnian = min($njlist); # 最近毕业年 $banji = new \app\teach\model\Banji; diff --git a/app/tools/controller/File.php b/app/tools/controller/File.php index 126097b7..43f677fa 100755 --- a/app/tools/controller/File.php +++ b/app/tools/controller/File.php @@ -98,8 +98,17 @@ class File extends BaseController // 获取表单上传文件 $file = request()->file('file'); - $data = $this->saveFileInfo($file, $list, true); + $list['file'] = $file; + // 验证表单数据 + $validate = new \app\tools\validate\File; + $result = $validate->check($list); + $msg = $validate->getError(); + if(!$result){ + return json(['msg' => $msg, 'val' => 0]); + }else { + $data = $this->saveFileInfo($file, $list, true); + } return json($data); } } diff --git a/app/tools/validate/File.php b/app/tools/validate/File.php new file mode 100644 index 00000000..5b1d0c5a --- /dev/null +++ b/app/tools/validate/File.php @@ -0,0 +1,29 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = [ + 'file|文件格式必须为jpg,jpeg,png,xls,xlsx' => 'fileExt:jpg,png,jpeg,xls,xlsx' + ]; + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = [ + + ]; +}