文件上传控件的赋值问题
我现在使用一个文件上传控件,HTML代码如下:
<INPUT TYPE=FILE Name='...'>
我可以在输入区输入文件名,也可以通过浏览按钮选择文件上传,
但现在我要通过程序赋值,死活赋不上,程序如下:
thisform=document.forms[0]
for (i=0;i<thisform.item.length;i++){
thisitem=thisform.item(i)
if (thisitem.name == '...'){
thisitem.value = 'c:\\aaa.doc'
alert(thisitem.value)
}
}
结果alert的结果死活是空,请各位大侠帮帮忙,谢了
问题点数:100、回复次数:6Top
1 楼qq5552661(DHTML&ASP)回复于 2002-02-08 23:41:22 得分 10
很简单啊..没有权限..Top
2 楼karma(无为MS MVP)回复于 2002-02-09 02:06:55 得分 30
for security reasons, the browser cannot allow you to set the value for <input type="file" ..>
Imagine you could, and you know Mr. qq5552661(DHTML&ASP) is visiting your site and he has a secret file "c:\secret.txt". You can add a hidden form and upload the file sercretly as follows, do you think that is good?
<FORM NAME="oForm"
ACTION="repost.asp"
ENCTYPE="multipart/form-data"
METHOD="post">
<INPUT TYPE="file" NAME="oFile1"/>
</FORM>
<script language="javascript">
function window.onload()
{
document.oForm.oFile1.value = "c:\\secret.txt"; //does not work
document.oForm.submit();
}
</script>
Top
3 楼linshao16(linshao)回复于 2002-02-09 09:21:19 得分 0
看来没有办法了,再问个问题:修改注册表中哪一项可以取消关于ActiveX控件的警告提示?Top
4 楼karma(无为MS MVP)回复于 2002-02-09 10:30:30 得分 30
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Internet
Settings\Zones\0
Change the 1201 DWORD from 1 to 0
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet
Settings\Zones\0
Change the 1201 DWORD from 1 to 0
Top
5 楼net_lover(【孟子E章】)回复于 2002-02-18 14:15:28 得分 10
出于安全方面的原因,不能赋值的Top
6 楼net_lover(【孟子E章】)回复于 2002-02-18 14:22:07 得分 20
由于安全方面的原因,IE4/5不支持在<input type=file>里设定值。但在NN4+里,必须先进行授权才能往<input type=file>里写值。以下是例子;在NN4.77里测试成功!!
<SCRIPT>
function test(){
if (document.layers) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalFileRead');
}
document.aForm.aFile.value = 'c:\\test.txt';
}
</SCRIPT>
<FORM NAME="aForm" METHOD="post" ENCTYPE="multipart/form-data" ACTION="你的事件处理代码">
<INPUT TYPE="file" NAME="aFile">
<INPUT TYPE="button" VALUE="测试文件" onclick="test()">
</FORM>Top




