Fixed the "bad file" bugs #7

This commit is contained in:
Azareal 2018-05-11 17:22:42 +10:00
parent b1d28b3046
commit 3801232d93
3 changed files with 12 additions and 0 deletions

View File

@ -319,6 +319,9 @@ func routeAccountEditAvatarSubmit(w http.ResponseWriter, r *http.Request, user c
var filename, ext string
for _, fheaders := range r.MultipartForm.File {
for _, hdr := range fheaders {
if hdr.Filename == "" {
continue
}
infile, err := hdr.Open()
if err != nil {
return common.LocalError("Upload failed", w, r, user)
@ -364,6 +367,9 @@ func routeAccountEditAvatarSubmit(w http.ResponseWriter, r *http.Request, user c
}
}
}
if ext == "" {
return common.LocalError("No file", w, r, user)
}
err := user.ChangeAvatar("." + ext)
if err != nil {

View File

@ -50,6 +50,9 @@ func CreateReplySubmit(w http.ResponseWriter, r *http.Request, user common.User)
}
for _, file := range files {
if file.Filename == "" {
continue
}
log.Print("file.Filename ", file.Filename)
extarr := strings.Split(file.Filename, ".")
if len(extarr) < 2 {

View File

@ -422,6 +422,9 @@ func CreateTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User)
}
for _, file := range files {
if file.Filename == "" {
continue
}
common.DebugLog("file.Filename ", file.Filename)
extarr := strings.Split(file.Filename, ".")
if len(extarr) < 2 {