Update zh 04.5.md
This commit is contained in:
@@ -7,14 +7,14 @@
|
|||||||
multipart/form-data 不对字符编码。在使用包含文件上传控件的表单时,必须使用该值。
|
multipart/form-data 不对字符编码。在使用包含文件上传控件的表单时,必须使用该值。
|
||||||
text/plain 空格转换为 "+" 加号,但不对特殊字符编码。
|
text/plain 空格转换为 "+" 加号,但不对特殊字符编码。
|
||||||
|
|
||||||
所以,表单的html代码应该类似于:
|
所以,创建新的表单html文件, 命名为upload.gtpl, html代码应该类似于:
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>上传文件</title>
|
<title>上传文件</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form enctype="multipart/form-data" action="http://127.0.0.1:9090/upload" method="post">
|
<form enctype="multipart/form-data" action="/upload" method="post">
|
||||||
<input type="file" name="uploadfile" />
|
<input type="file" name="uploadfile" />
|
||||||
<input type="hidden" name="token" value="{{.}}"/>
|
<input type="hidden" name="token" value="{{.}}"/>
|
||||||
<input type="submit" value="upload" />
|
<input type="submit" value="upload" />
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
fmt.Fprintf(w, "%v", handler.Header)
|
fmt.Fprintf(w, "%v", handler.Header)
|
||||||
f, err := os.OpenFile("./test/"+handler.Filename, os.O_WRONLY|os.O_CREATE, 0666)
|
f, err := os.OpenFile("./test/"+handler.Filename, os.O_WRONLY|os.O_CREATE, 0666) // 此处假设当前目录下已存在test目录
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user