关于表单中的问题

alidiedie 2003-08-10 11:19:19
请看如下代码:
<FORM METHOD="POST" ACTION="upload.asp" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>

这段代码是利用某个文件上传组件时需要的。
在text框输入要上传的文件名,或者点右侧的浏览框,就可以选择要上传的文件。

请问<intput type = file..>
这里的file就是一个对象,它有哪些属性呢?怎么设置那个文本框和浏览按钮为不可见(隐藏的,效果和type = hidden类似,不显示,但按下submit后,数据仍然提交)。
虽然隐藏,但是可以使用file的一些属性设置要上传的文件名。

我要达到的目的是:不显示文本输入框,按下按钮就可以把指定的文件上传了。

谢谢大家
...全文
146 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
possible_Y 2003-08-10
  • 打赏
  • 举报
回复
<script>
function cha(obj){
file1.focus();
var WshShell=new ActiveXObject("WScript.Shell")
WshShell.sendKeys(obj.value)
}
</script>
<input id=file1 type=file>
<input type="text" name="go" onblur="cha(this)">
possible_Y 2003-08-10
  • 打赏
  • 举报
回复
<input name=file1 type=file style="display: none">
Jaron 2003-08-10
  • 打赏
  • 举报
回复
http://www.experts-exchange.com/Web/Q_20297382.html


upload.hta
===========
<html>
<head>
<title>Loading And Posting Files</title>
<script language="javascript">
//set your full folder path
var szFolder = "e:/"
//set your file name
var szURL = "mydata.doc";
var oHTTP = new ActiveXObject("Msxml2.XMLHTTP");
oHTTP.open("GET",szFolder + szURL,false);
oHTTP.send();
alert(szURL);
var oHTTP2 = new ActiveXObject("Msxml2.XMLHTTP");
oHTTP2.open("POST","http://localhost/experts-exchange/post.asp?URL=" + szURL,false,"user","pwd");
oHTTP2.send(oHTTP.responseBody);
alert(oHTTP2.responseText);
</script>
</head>
</html>

post.asp
========
<%@language="VBScript"%>
<%
Response.Buffer = True
On Error Resume Next
Dim oStream, szMsg, szURL
szURL = Request.QueryString("URL")
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Type = 1
oStream.Open
oStream.Write Request.BinaryRead(Request.TotalBytes)
If Err Then
szMsg = "Error Encountered In Writing Data 0x" & Hex(Err.Number) & " - " & Err.Description & vbcrlf
Else
szMsg = "Data Successfully Written: Total Size - " & oStream.Size & " bytes" & vbcrlf
End If
'you must have a folder called downloads
'this command will not create the folder
szURL = Server.MapPath("downloads/" & szURL)
oStream.SaveToFile szURL, 2
If Err Then
szMsg = szMsg & "Failure To Save File 0x" & Hex(Err.number) & " - " & Err.Description
Else
szMsg = szMsg & "Success In Saving File At " & szURL
End If
oStream.Close
Set oStream = Nothing
%>Results Of Operations...
<%=szMsg%>

RadishRabbitGao 2003-08-10
  • 打赏
  • 举报
回复
你想干什么呢?
RadishRabbitGao 2003-08-10
  • 打赏
  • 举报
回复
试试便知
alidiedie 2003-08-10
  • 打赏
  • 举报
回复
to RadishRabbitGao
你说的disabled只是禁止该input而已啊。

to ALL:
如果真象唐伯虎说说的那样,不显示input file的文本框,又要达到文件上传功能的话,该怎么做呢?大家可以讨论可行性
alidiedie 2003-08-10
  • 打赏
  • 举报
回复
我觉得唐伯虎说的有道理,我在另一个论坛也看到了这样的reply:
You can't for security reasons. If you could, then someone could accidentally upload a file if they didn't change the value. This way, it forces the user to select a file to upload, otherwise, it uploads none.
RadishRabbitGao 2003-08-10
  • 打赏
  • 举报
回复
唐伯虎此言差矣
RadishRabbitGao 2003-08-10
  • 打赏
  • 举报
回复
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50" DISABLED><BR>
Jaron 2003-08-10
  • 打赏
  • 举报
回复
这个属性不可以设置默认值。
试想,你用 <INPUT TYPE="FILE" NAME="FILE1" value=c:\winnt\system32\abc.ini> 那该有多危险。MS已经考虑到这个安全性的问题了。呵呵
alidiedie 2003-08-10
  • 打赏
  • 举报
回复
唐伯虎的方法是不错,但我在原始网页上看到有下列限制,我实验了,也确实如此:
Notes
=====
1. You are still bound by the restrictions of the browser. The *.hta file MUST be opened locally and not reside on a web server.

2. If you wish to persist data onto your client, you can use cookies. They however have a limitation of 4kb. You can use the userData behaviors available with MSIE5+. This behavior has a limit of 64Kb.

3. What you describe can be done within an Intranet but on the Internet, it will fail most of the time because of the settings of MSIE and this is by design to protect users from hackers.

第一条显示这个upload.htm只能在本地打开,而不能从服务器上下载,这个比较麻烦,怎么修改就可以呢?

我正在实验 一切皆可能的 方法
mtide 2003-08-10
  • 打赏
  • 举报
回复
Jaron(唐伯虎点蚊香)的方法不错啊
victent 2003-08-10
  • 打赏
  • 举报
回复
<input type=file>它没有hidden的功能!

…………………………
http://www.nuoteware.com
欢迎大家的加盟
…………………………

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧