func fupload(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
r.ParseForm()
company := r.FormValue("company")
fmt.Println(company)
_, header, _ := r.FormFile("upfile")
fmt.Println(header.Filename)
return
}
w.Write([]byte("<html><body>"))
w.Write([]byte(fmt.Sprintf("<form method=\"POST\" enctype=\"multipart/form-data\">")))
w.Write([]byte("Enter Company <input type=\"text\" maxlength=\"80\" size=\"80\" name=\"company\" ><br/>"))
w.Write([]byte("File to upload: <input type=\"file\" name=\"upfile\" /><br/>"))
w.Write([]byte("<input type=\"submit\" value=\"Submit\"/>"))
w.Write([]byte("</form>"))
w.Write([]byte("</body></html>"))
return
}
对于输入类型 Text (eg) Company 这里总是返回 NULL,当 enctype="multipart/form-data"
RISEBY
海绵宝宝撒
相关分类