在c.savatofile中必须加 . 在做数据库存储是不需要的,数据库存储时,字符默认非空
取文件的后缀名,path.Ext
artiName := c.GetString("articleName") //1.get data
artiContent := c.GetString("content")
beego.Info(artiName,artiContent)
f, h, err := c.GetFile("uploadname")
defer f.Close()
fileext := path.Ext(h.Filename)
if fileext != ".jpg" && fileext != ".png" {
beego.Info("ipload file err",err)
}
beego.Info(fileext)
避免文件名重复会被覆盖
```go
filename := time.Now().Format("2006-01-02 15:04:05") + fileext
fileext 是取出来的后缀名,fprmat格式化输出字符串
if err != nil {
beego.Info("upload file failed")
} else {
c.SaveToFile("uploadname","./static/img/" + filename)
}