From e0b4b42ec6d379490ef3221d9db277b0338ee92c Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Wed, 6 Mar 2019 09:42:21 +0800 Subject: [PATCH] Fix: file rename validate --- application/index/model/FileManage.php | 18 +++++++++++++----- application/index/view/home/home.html | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/application/index/model/FileManage.php b/application/index/model/FileManage.php index e9439e09..9f04abcf 100644 --- a/application/index/model/FileManage.php +++ b/application/index/model/FileManage.php @@ -160,12 +160,19 @@ class FileManage extends Model{ $originFolder = $fname; $new = str_replace("/", "", self::getFileName($new)[0]); if(!$notEcho){ - $new = str_replace(" ", "", $new); + $newToBeVerify = str_replace(" ", "", $new); + } + //检查是否全为空格 + $varifyExplode = explode(".",$newToBeVerify); + $isFullBlackspace = false; + foreach ($varifyExplode as $key => $value) { + if($value == ""){ + $isFullBlackspace = true; + break; + } } - $newSuffix = explode(".",$new); - // 文件名带有‘.’会导致验证失败 - $newPrefix = str_replace($newSuffix, "", $new); - if(!self::fileNameValidate($newPrefix)){ + $toBeValidated = str_replace(".","",$newToBeVerify); + if(!self::fileNameValidate($toBeValidated) || $isFullBlackspace){ if($notEcho){ return '{ "result": { "success": false, "error": "文件名只支持汉字、字母、数字和下划线_及破折号-" } }'; } @@ -184,6 +191,7 @@ class FileManage extends Model{ self::folderRename($originFolder,$folderTmp,$uid,$notEcho); die(); } + $newSuffix = explode(".",$new); $originSuffix = explode(".",$fileRecord["orign_name"]); if(end($originSuffix) != end($newSuffix)){ if($notEcho){ diff --git a/application/index/view/home/home.html b/application/index/view/home/home.html index 7cb0d1b9..a5222d7b 100644 --- a/application/index/view/home/home.html +++ b/application/index/view/home/home.html @@ -35,6 +35,7 @@ apiURL={ imgThumb:"/File/Thumb" }; + mediaType = {}