From 6d5105b5cd022c219feeb692f3ef7a85cd723902 Mon Sep 17 00:00:00 2001 From: printempw Date: Thu, 22 Sep 2016 22:00:12 +0800 Subject: [PATCH] check mime type of file out of laravel validator --- app/Http/Controllers/SkinlibController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/SkinlibController.php b/app/Http/Controllers/SkinlibController.php index 4add492e..f0b5c15e 100644 --- a/app/Http/Controllers/SkinlibController.php +++ b/app/Http/Controllers/SkinlibController.php @@ -242,11 +242,15 @@ class SkinlibController extends Controller private function checkUpload(Request $request) { $this->validate($request, [ - 'name' => 'required|no_special_chars', - 'file' => 'required|mimes:png|max:10240', + 'name' => 'required|no_special_chars', + 'file' => 'required|max:10240', 'public' => 'required' ]); + if ($_FILES['file']['type'] != "image/png" || $_FILES['file']['type'] != "image/x-png") { + return json("文件格式不对哦", 1); + } + // if error occured while uploading file if ($_FILES['file']["error"] > 0) return json($_FILES['file']["error"], 1);