package main import ( "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" ) // Upload uploads files to /tmp . func Upload(r *ghttp.Request) { saveDirPath := "/tmp/" files := r.GetUploadFiles("file") if _, err := files.Save(saveDirPath); err != nil { r.Response.WriteExit(err) } r.Response.WriteExit("upload successfully") } // UploadShow shows uploading simgle file page. func UploadShow(r *ghttp.Request) { r.Response.Write(` GF Upload File Demo
`) } // UploadShowBatch shows uploading multiple files page. func UploadShowBatch(r *ghttp.Request) { r.Response.Write(` GF Upload Files Demo
`) } func main() { s := g.Server() s.Group("/upload", func(group *ghttp.RouterGroup) { group.POST("/", Upload) group.ALL("/show", UploadShow) group.ALL("/batch", UploadShowBatch) }) s.SetPort(8199) s.Run() }