Compare commits

...

2 Commits

1 changed files with 8 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"mime/multipart" "mime/multipart"
"os" "os"
"path" "path"
"regexp"
"time" "time"
"videoplayer/dao" "videoplayer/dao"
"videoplayer/proto" "videoplayer/proto"
@ -83,6 +84,13 @@ func CreateConfigFile(req *proto.ConfigFileReq, userId int) error {
} }
//查看系统中是否存在文件,不存在则创建 //查看系统中是否存在文件,不存在则创建
file := req.FilePath + "/" + req.FileName file := req.FilePath + "/" + req.FileName
//正则判断文件名是否合法
pattern := `^/([^/:\*?]+/)*([^/:\*?]+)?$`
reg := regexp.MustCompile(pattern)
if reg.MatchString(file) == false {
err = fmt.Errorf("file path is invalid")
return err
}
_, err = os.Stat(file) _, err = os.Stat(file)
if err != nil { if err != nil {
//创建文件 //创建文件