高手们!问题来了,还是有关图片上传时的客户端判断的问题,马上给分。

aocool 2003-10-17 10:04:33
下面是我的源代码。
我想一下子上传多个图片,然后分别判断图片的合法性。

但是问题来了,一两个文件的时候还可以。多了就不行。
好像是循环到第三个文件域的时候就过不去了。但是拿光标点一下
其中任何一个文件域就又可以了。靠,真是变态。

是不是有办法让程序慢慢的一个一个的判断?

哪位能解决,马上给分并致谢,最好讲出道理来,我想了一下午想不明白。
书崩溃了。:(

源代码:
复制另存为.htm就可以。谢谢了。。


<html>
<head>
<title>我的图片上传检测</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<link rel="stylesheet" href="../Common/Css/Comon.css" type="text/css">
</head>

<body bgcolor="#ffffff" text="#000000" leftmargin="0" topmargin="0" onLoad="MM_preloadImages('../images/mainf2.gif')">
<table width="778" align="center" height="420">
<tr bgcolor="#FFFFFF">
<td align="center" valign="top">
<form method="POST" name="frmManage" enctype="multipart/form-data" action="ContentSave.asp?CodeID=020101&CSS=1235" onSubmit="return check()">
<input type="hidden" name="userName" value="zhoutao">
<input type="hidden" name="CSS" value="1235">
<input type="hidden" name="CodeID" value="020101">
<input type="hidden" name="selectBodyColor" value="">
<input type="hidden" name="selectFontColor" value="">
<input type="hidden" name="selectFontSize" value="">
<table width="778" border="1" cellspacing="1" cellpadding="1" bgcolor="#003366" bordercolor="#FFFFFF">
<tr bgcolor="#003366" align="center">
<td colspan="3" height="25"><font size="3" color="#FFFFFF"><b>内容录入</b></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="20%" align="right"><b>标题</b>:</td>
<td colspan="2"> <input type="text" name="txtTitle" size="50" maxlength="100" class="inte">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="20%" align="right"><strong>关键字</strong> :</td>
<td colspan="2"><input name="tfkey" type="text" id="tfkey" size="20" maxlength="20" class="inte">
<font color="#FF0000">(请输入标题关键字,以利于新闻搜索功能!)</font></td>
</tr>
<tr valign="bottom" bgcolor="#FFFFFF">
<td colspan="2" height="20"><b>请填写内容部分</b>:</td>
<td height="20" width="39%"><b>更改人</b>: 就是大哥你了。:)</td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="3">
<table align=center><tr><td>第 <font color=#ff0000>1</font> 部分:</td></tr></table><table width=100% border=0 cellspacing=1 cellpadding=1 bgcolor=#003366><tr bgcolor=#FFFFFF><td width='50%' height=100 align=center><font color=#0000FF>请选择图片文件:</font><input type=file name='file1' class=inte title=1><br><font color=#0000FF>请输入此图片的注释!</font><input type=input name='memo1' class=inte></td><td width='50%' height=100 align=center><BR><font color=#0000FF>请录入文章内容:</font><BR><TEXTAREA rows=6 cols=55 name='txtContent1' class=inte></TEXTAREA><BR><BR></td></tr></Table><table align=center><tr><td>第 <font color=#ff0000>2</font> 部分:</td></tr></table><table width=100% border=0 cellspacing=1 cellpadding=1 bgcolor=#003366><tr bgcolor=#FFFFFF><td width='50%' height=100 align=center><BR><font color=#0000FF>请录入文章内容:</font><BR><TEXTAREA rows=6 cols=55 name='txtContent2' class=inte></TEXTAREA><BR><BR></td><td width='50%' height=100 align=center><font color=#0000FF>请选择图片文件:</font><input type=file name='file2' class=inte title=1><br><font color=#0000FF>请输入此图片的注释!</font><input type=input name='memo2' class=inte><input type=hidden name='hidDir2' value=''></td></tr></Table><table align=center><tr><td>第 <font color=#ff0000>3</font> 部分:</td></tr></table><table width=100% border=0 cellspacing=1 cellpadding=1 bgcolor=#003366><tr bgcolor=#FFFFFF><td width='50%' height=100 align=center><font color=#0000FF>请选择图片文件:</font><input type=file name='file3' class=inte title=1><br><input type=hidden name='hidDir3' value=''><font color=#0000FF>请输入此图片的注释!</font><input type=input name='memo3' class=inte></td><td width='50%' height=100 align=center><font color=#0000FF>请选择图片文件:</font><input type=file name='file13' class=inte title=1><br><input type=hidden name='hidDir13' value=''><font color=#0000FF>请输入此图片的注释!</font><input type=input name='memo13' class=inte></td></tr></Table><table align=center><tr><td>第 <font color=#ff0000>4</font> 部分:</td></tr></table><table width=100% border=0 cellspacing=1 cellpadding=1 bgcolor=#003366><tr bgcolor=#FFFFFF><td width='100%' align=center height=100><font color=#0000FF>请选择图片文件:</font><input type=file name='file4' class=inte title=1><br><input type=hidden name='hidDir4' value=''><font color=#0000FF>请输入此图片的注释!</font><input type=input name='memo4' class=inte></td></tr></Table> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="3"> <div align="center">
<input type="submit" name="Submit" value=" 保 存 ">
</div></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>

<script language="javascript">
<!--
//save The content To Data Page.
function check()
{
var lenVar;
var tout;
window.clearTimeout(tout);
lenVar=document.frmManage.txtTitle.value
if (document.frmManage.txtTitle.value=="")
{
alert("标题不能为空!")
document.frmManage.txtTitle.focus();
document.frmManage.Submit.disabled=false;
return false;
}
if (lenVar.length>100)
{
alert("对不起!您的标题过长,请不要超过50个汉字");
document.frmManage.Submit.disabled=false;
return false;
}
for(i=0;i<document.frmManage.elements.length;i++)
{

if (document.frmManage.elements[i].type=="file")
{
//document.frmManage.elements[i].focus();
if (document.frmManage.elements[i].value=="")
{alert('请选择您要上传的图片!');
document.frmManage.elements[i].focus();
document.frmManage.Submit.disabled=false;
return false;
}
document.frmManage.Submit.disabled=true;
var img=new Image();
var imagewidth,imageheigth,fsize,myoffset,okoffset;
img.src=document.frmManage.elements[i].value;
if(document.frmManage.elements[i].title=='1')
okoffset=1.33;
if(document.frmManage.elements[i].title=='2')
okoffset=0.75;
if(img.readyState!="complete")
{
tout=window.setTimeout("check()",50);
return false;
//return false;
}
else
{
imagewidth=img.width;
imageheigth=img.height;
myoffset=imagewidth/imageheigth
myoffset=myoffset.toFixed(2);
fsize=img.fileSize/1024;
fsize=fsize.toFixed(1);
if (myoffset>okoffset+0.1 || myoffset<okoffset-0.1)
{alert('上传的图片长宽比例不合法,请修改后重试!');
document.frmManage.elements[i].focus();
document.frmManage.Submit.disabled=false;
return false;}
if(fsize>300)
{alert('上传的图片大小超出限制,最大为300KB!');
document.frmManage.elements[i].focus();
document.frmManage.Submit.disabled=false;
return false;}
}
}
}
//document.frmManage.Submit.disabled=false;
return true;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
...全文
222 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
longshenwang 2003-10-17
  • 打赏
  • 举报
回复
UP...
孟子E章 2003-10-17
  • 打赏
  • 举报
回复
<%
Response.Write Request("a")
%>
<form method=post onsubmit="a.value=document.all.x.width + ':' + document.all.x.height">
<input name=a type=hidden>
<input type=file name=f onpropertychange='document.all.x.src=f.value'>
<input type=submit onclick="alert(document.all.x.width + ':' + document.all.x.height)">
<img id=x style="visibility:hidden">
</form>
孟子E章 2003-10-17
  • 打赏
  • 举报
回复
<%
Response.Write Request("a")
%>
<form method=post onsubmit="a.value=document.all.x.width + ':' + document.all.x.height">
<input name=a type=hidden>
<input type=file name=f onpropertychange='document.all.x.src=f.value'>
<input type=submit onclick="document.all.x.width + ':' + document.all.x.height">
<img id=x style="visibility:hidden">
</form>
孟子E章 2003-10-17
  • 打赏
  • 举报
回复
<%
Response.Write Request("a")
%>
<form method=post onsubmit="a.value=document.all.x.width + ':' + document.all.x.height">
<input name=a type=hidden>
<input type=file name=f onpropertychange='document.all.x.src=f.value'>
<input type=submit>
<img id=x style="visibility:hidden">
</form>
aocool 2003-10-17
  • 打赏
  • 举报
回复
up 以下
yonghengdizhen 2003-10-17
  • 打赏
  • 举报
回复
to aocool(知秋一叶)

可是问题还是没有解决,我想知道为什么我的循环检测的方法不行

ie是多线程序应用程序,但是在处理状态检测时是同步的.
aocool 2003-10-17
  • 打赏
  • 举报
回复
感谢各位。。。


可是问题还是没有解决,我想知道为什么我的循环检测的方法不行。

还有,在浏览文件的同时进行检测是可以,但是如果不合规定怎么把那个文件域里的东西清空呢?文件域的value是只读的。

请教高手。谢谢
yonghengdizhen 2003-10-17
  • 打赏
  • 举报
回复
<%
kch = Request.QueryString("kch")
caseno = Request.QueryString("caseno")
lx=Request.QueryString ("lx")
%>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK rel="stylesheet" type="text/css" href="../inc/en.CSS">
<script language="javascript" src="../inc/DateObject.js"></script>
<script language="javascript" src="../inc/main.js"></script>
<title>现场照片</title>
<!--#include file="../INC/bgsub.asp" -->
<script language="javascript">
function CheckData()
{
nLimFileSize=parseInt(document.all.FILE_SIZE.value);
nLimWidth=parseInt(document.all.PICTURE_WIDTH.value);
nLimHeight=parseInt(document.all.PICTURE_HEIGHT.value);
for(i=0;i<document.getElementsByName("Name").length;i++)
{
oName=document.getElementsByName("Name")[i];
oFile=document.getElementsByName("FilePath")[i];
nFileSize=frames["_hideFrame"].document.all.VerifyTable.rows[i].all.tags("img")[0].fileSize;
nWidth=frames["_hideFrame"].document.all.VerifyTable.rows[i].all.tags("img")[0].width;
nHeight=frames["_hideFrame"].document.all.VerifyTable.rows[i].all.tags("img")[0].height;
if(oName.value=="")
{
oName.focus();
alert("名称不能为空!");
return false;
}
if(nFileSize==-1)
{
oFile.focus();
alert("图片为空或类型无效!");
return false;
}
if(nFileSize>nLimFileSize)
{
oFile.focus();
alert("图片文件太大,请限制在" + nLimFileSize + "字节以内!");
return false;
}
if(nWidth>nLimWidth||nHeight>nLimHeight)
{
oFile.focus();
alert("图片太大,请限制在" + nLimWidth + "X" + nLimHeight + "大小!");
return false;
}
}
document.all.img.innerHTML="<div style='position:absolute;border:4px groove pink'><font size=2 color=red>开始保存图片,请耐心等待....</font></div>"
}
function AddMoreRow()
{
oRow=event.srcElement.parentNode.parentNode;
oTable=event.srcElement.parentNode.parentNode.parentNode.parentNode;
oNewRow=oTable.insertRow();
for(i=0;i<oRow.cells.length;i++)
{
oNewRow.insertCell().innerHTML=oRow.cells[i].innerHTML;
}
oRow.all("DelBtn").disabled=false;
oNewRow.all("DelBtn").disabled=false;
oNewRow.className="content";
frames["_hideFrame"]._AddMoreRow();
}
function DeleteThisRow()
{
oRow=event.srcElement.parentNode.parentNode;
oTable=event.srcElement.parentNode.parentNode.parentNode.parentNode;
if(oTable.rows.length>1)
{
frames["_hideFrame"]._DeleteThisRow(oRow.rowIndex);
oTable.deleteRow(oRow.rowIndex);
if(oTable.rows.length==1)
{
oTable.all("DelBtn").disabled=true;
}
}
}
function DisabledKeyInput()
{
if(event.keyCode!=8&&event.keyCode!=46) event.returnValue=false;
}
function HidePreviewPicture()
{
document.all.img.innerHTML="";
}
function VerifyPicture()
{
nLimFileSize=parseInt(document.all.FILE_SIZE.value);
nLimWidth=parseInt(document.all.PICTURE_WIDTH.value);
nLimHeight=parseInt(document.all.PICTURE_HEIGHT.value);
oRow=event.srcElement.parentNode.parentNode;
oImg=frames["_hideFrame"].document.all.VerifyTable.rows[oRow.rowIndex].all.tags("img")[0];
oImg.src=event.srcElement.value;
document.all.img.innerHTML="<img src='" + event.srcElement.value + "'>"
document.all.img.childNodes[0].attachEvent("onerror",HidePreviewPicture)
if(oImg.readyState=="complete")
{
if(oImg.fileSize==-1)
{
alert("文件类型无效!")
}
else if(oImg.fileSize>nLimFileSize)
{
alert("图片文件太大,请限制在" + nLimFileSize + "字节以内!")
}
else if(oImg.width>nLimWidth||oImg.height>nLimHeight)
{
alert("图片太大,请限制在" + nLimWidth + "X" + nLimHeight + "大小!")
}
}
}
</script>
</HEAD>
<body <%=rightkey%> class=scrollbar1 topmargin=10>
<form target="_hideFrame" method=post enctype="multipart/form-data" action="BatchAddPicture_DB.asp?kch=<%=kch%>&caseno=<%=caseno%>&lx=<%=lx%>" onsubmit="return CheckData()">
<table>
<tr>
<td>
<a href="xckcpiclisttp.asp?kch=<%=kch%>&caseno=<%=caseno%>&lx=<%=lx%>" id=BackLink><img SRC="../../images/back.gif" BORDER="0" WIDTH="48" HEIGHT="19"></a>
</td>
</tr>
</table>
<%call bghead()%>
<table><th><%=lx%>批量上传</th></table>
<%call bgmid()%>
<table style="color:<%=session("color")%>;font-size:<%=session("size")%>">
<tr class=content>
<td nowrap>名称*</td>
<td><input type="text" name="Name" size=15 maxlength="50"></td>
<td nowrap>文件路径*</td>
<td>
<input type=file name="FilePath" size=15 onkeydown="DisabledKeyInput()" onpropertychange="VerifyPicture()">
</td>
<td nowrap>说明</td><td><input type=text name=Description size=45><input type="button" class="input1" value="增加" onclick="AddMoreRow()"></td>
<td nowrap> <input type="button" class="input1" id=DelBtn value="删除" disabled onclick="DeleteThisRow()"></td>
</tr>
</table>
<table style="color:<%=session("color")%>;font-size:<%=session("size")%>">
<tr align =center>
<td class="tijiao" align =center>
 <input type="submit" class="input1" value="保存" id=submit1 name=submit1>  <input type="reset" class="input1" value="取消" id=reset1 name=reset1>
</td>
</tr>
</table>
<iframe src="about:blank" width=100% height=0 name="_hideFrame"></iframe>
<%caLL bgbottom()%>
<div id="img"></div>
<div id=tempHTML style="display:none">
<script>
function _AddMoreRow()
{
oCell=document.all.VerifyTable.insertRow().insertCell();
oImg=document.createElement("img");
oImg.attachEvent("onreadystatechange",_VerifyPicture);
oImg.attachEvent("onerror",_PictureError);
oCell.appendChild(oImg);
}
function _DeleteThisRow(rowIndex)
{
document.all.VerifyTable.deleteRow(rowIndex);
}
function _PictureError()
{
if(event.srcElement.fileSize==-1)
{
alert("无效的图片类型!");
}
}
function _VerifyPicture()
{
oImg=event.srcElement;
if(oImg.readyState=="complete")
{
nWidth=parseInt(parent.document.all.PICTURE_WIDTH.value);
nHeight=parseInt(parent.document.all.PICTURE_HEIGHT.value);
nFileSize=parseInt(parent.document.all.FILE_SIZE.value);
if(oImg.width>nWidth||oImg.height>nHeight)
{
alert("图片尺寸太大,请限制在" + nWidth + "X" + nHeight + "大小!")
}
else if(oImg.fileSize>nFileSize)
{
alert("图片文件超出限定大小,请限定在" + nHeight + "字节以内!")
}
}
}
</script>
<table border=0 id=VerifyTable>
<tr><td><img border=0 onerror="_PictureError()" onreadystatechange="_VerifyPicture()"></td></tr>
</table>
</div>
<script language=javascript>
function InitFrame()
{
frames["_hideFrame"].document.write(document.all.tempHTML.innerHTML);
}
window.onload=InitFrame;
</script>
</form>
</BODY>
</HTML>
<!--#include file="../inc/foot.inc"-->
<!--#include file="../inc/title.asp"-->

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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