feat:增加图片格式

This commit is contained in:
lifei6671 2019-02-27 17:32:06 +08:00
parent 491834e6b1
commit c91520a04d
2 changed files with 13 additions and 1 deletions

View File

@ -419,7 +419,7 @@ func (c *DocumentController) Upload() {
filePath := filepath.Join(conf.WorkingDirectory, "uploads", identify)
//将图片和文件分开存放
if strings.EqualFold(ext, ".jpg") || strings.EqualFold(ext, ".jpeg") || strings.EqualFold(ext, ".png") || strings.EqualFold(ext, ".gif") {
if filetil.IsImageExt(moreFile.Filename) {
filePath = filepath.Join(filePath, "images", fileName+ext)
} else {
filePath = filepath.Join(filePath, "files", fileName+ext)

View File

@ -224,6 +224,18 @@ func HasFileOfExt(path string,exts []string) bool {
return err == os.ErrExist
}
// IsImageExt 判断是否是图片后缀
func IsImageExt(filename string) bool {
ext := filepath.Ext(filename)
return strings.EqualFold(ext, ".jpg") ||
strings.EqualFold(ext, ".jpeg") ||
strings.EqualFold(ext, ".png") ||
strings.EqualFold(ext, ".gif") ||
strings.EqualFold(ext,".svg") ||
strings.EqualFold(ext,".bmp") ||
strings.EqualFold(ext,".webp")
}
//忽略字符串中的BOM头
func ReadFileAndIgnoreUTF8BOM(filename string) ([]byte,error) {