input type=file - HTML元素

来源:百度文库 编辑:神马文学网 时间:2024/04/27 20:13:54
定义
创建文件上载控件,该控件带有一个文本框和一个浏览按钮。
Creates a file upload object with a text box and Browse button.
注释
要使得文件上载能够成功,要做到以下几点:
INPUT type=file 元素必须出现在 FORM 元素内。 必须为 INPUT type=file 元素指定 NAME 标签属性的值。 FORM 元素 METHOD 标签属性的值必须设置为 post。 FORM 元素 ENCTYPE 标签属性的值必须设置为 multipart/form-data。
要处理上载到服务器的文件,服务器端进程必须可以处理 multipart/form-data 的提交。例如,Microsoft Posting Acceptor 能够允许 Microsoft Internet Information Server (IIS) 接受文件上载。而在网上也可找到其它的 Common Gateway Interface (CGI) 脚本用于处理 multipart/form-data 提交。
此元素在 Internet Explorer 4.0 及以上版本的 HTML 和脚本中可用。而文件上载 add-on 要求在 Internet Explorer 3.02 中使用 INPUT type=file 元素。用户可以在文本框中输入文件路径或者单击浏览按钮在文件系统中浏览。
此元素是一个内嵌元素。
此元素不需要关闭标签。
For a file upload to take place:
The INPUT type=file element must be enclosed within a FORM element. A value must be specified for the NAME attribute of the INPUT type=file element. The METHOD attribute of the FORM element must be set to post. The ENCTYPE attribute of the FORM element must be set to multipart/form-data.
To handle a file upload to the server, a server-side process must be running that can handle multipart/form-data submissions. For example, the Microsoft Posting Acceptor allows Microsoft Internet Information Server (IIS) to accept file uploads. Additional Common Gateway Interface (CGI) scripts that can handle multipart/form-data submissions are available on the Web.
The INPUT type=file element is available in HTML and script as of Internet Explorer 4.0. The file upload add-on is required to use the INPUT type=file element in Internet Explorer 3.02. Users can enter a file path in the text box or click the Browse button to browse the file system.
When a file is uploaded, the file name is also submitted. The path of the file is available only to the machine within the Local Machine security zone. The value property returns only the file name to machines outside the Local Machine security zone. See About URL Security Zones for more information on security zones.
This element is an inline element.
This element does not require a closing tag.
示例代码
下面的例子使用 INPUT type=file 元素将文件上载到服务器上。第一个例子要求 Microsoft Posting Acceptor, Microsoft Posting Acceptor 可与 IIS 或 Personal Web Server 一起使用。
该示例使用 HTML 代码提交用户选中的文件到 Cpshost.dll,该服务器组件由 Posting Acceptor 安装。
The following examples use the INPUT type=file element to upload a file to a server. The first example requires Microsoft Posting Acceptor, which can be used with IIS or Personal Web Server.
This example uses HTML code to submit a file selected by the user to Cpshost.dll, which is installed with Posting Acceptor.

下面的例子显示了 Repost.asp 的 ASP 内容。请注意,上载文件的属性可从提交表单中访问。
This example shows the Active Server Page (ASP) content of Repost.asp. Notice that the properties of the uploaded file are accessible from the submitted form.
<%@ LANGUAGE = JScript %><%   Response.buffer=true;%>Repost Example

Upload Status

Destination: <% Response.Write(Server.HTMLEncode(Request.Form("TargetURL"))) %>

<%    Response.write("

Name: " + Server.HTMLEncode(Request.Form("FileName")) + "

");    Response.write("

Size: " + Server.HTMLEncode(Request.Form("FileSize")) + "

");    Response.write("

Path: " + Server.HTMLEncode(Request.Form("FilePath")) + "

"); %> 另见
input