《无组件上传文件》

80酷酷网    80kuku.com

  上传|无组件我只是照搬过来的,我也是刚找到。我自己还没看明白源码呢。:)

你只有自己修改了。我把整个网页一起贴过来吧。谁英文好翻译一下。

一页贴不下,分两页。

Upload Form

Usually, you use an HTML FORM to submit data from the browser to the web server. That form can contain text fields, checkbox, button and also a file type control to upload files. The user fills in the form with his data and submits the form to the server.



The enctype attribute of the <FORM> element specifies the content type used to encode the form data set for submission to the server. The enctype attribute used by default is " application/x-www-form-urlencoded ". However, that enctype is inefficient for sending large quantities of text, text containing non-ASCII characters or binary data to the server. The content type " multipart/form-data " should be used to submit forms in case of file uploading. Actually, it can be used to submit files and binary data.



A " multipart/form-data " message contains a series of parts, where each part is expected to contain:



a Content-Disposition header whose value is " form-data "

a name attribute specifying the control name.

For a file type control, the part contains some more information:



a filename attribute specifying the original path and file name on the client

a Content-Type header of the binary data control sent.

Those headers are followed by the binary or text content of the control.



The following example illustrates " multipart/form-data " encoding. The client would have this form in the browser:



<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="upload.asp">

<INPUT TYPE="Text" NAME="email" VALUE="PhCollignonemail.com">


<INPUT TYPE="file" NAME="blob">


<INPUT TYPE="submit" NAME="Enter">

</FORM>







If this form is submitted, the following request can be read on the server:



-----------------------------7cf87224d2020a

Content-Disposition: form-data; name="email"



PhCollignonemail.com

-----------------------------7cf87224d2020a

Content-Disposition: form-data; name="blob"; filename="c:\image.gif"

Content-Type: image/pjpeg



ÿØÿàJFIFHHÿÛC…

…ÿÙ

-----------------------------7cf87224d2020a

Content-Disposition: form-data; name="Enter"



Submit Query

-----------------------------7cf87224d2020a--



That content can be displayed if it is sent back as a response to the client. The binary data should be read and written with Request.binaryRead and Response.binaryWrite methods.



<%

Response.BinaryWrite(Request.BinaryRead(Request.TotalBytes))

%>



You can see that parts of the response are delimited by boundaries:



-----------------------------7cf87224d2020a



and the last boundary is followed by: ' -- '





There is one Content-Disposition for each control. The name attribute identifies the control sent by the HTML form (email, blob and Enter). For a file type control (blob), the file name is also part of Content-Disposition header and, a Content-Type header gives the content type of the binary data.



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: