ASP 上传大小限制 高手请来改下我的源码

<%Response.Expires=0Functionf_Bin2Str(ByValsBin)DimiI,iLen,iChr,iReiRe=""IfNotIsNull(... <%
Response.Expires=0
Function f_Bin2Str(ByVal sBin)
Dim iI, iLen, iChr, iRe
iRe = ""
If Not IsNull(sBin) Then
iLen = LenB(sBin)
For iI = 1 To iLen
iChr = MidB(sBin, iI, 1)
If AscB(iChr) > 127 Then
iRe = iRe & Chr(AscW(MidB(sBin, iI + 1, 1) & iChr))
iI = iI + 1
Else
iRe = iRe & Chr(AscB(iChr))
End If
Next
End If
f_Bin2Str = iRe
End Function
iConcStr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False" & _
";Data Source=" & server.mappath("zj.mdb")
iSql="tb_img"
set iRe=Server.CreateObject("ADODB.Recordset")
iRe.Open iSql,iConcStr,1,3
iLen=Request.TotalBytes
sBin=Request.BinaryRead(iLen)
iCrlf1 = ChrB(13) & ChrB(10)
iCrlf2 = iCrlf1 & iCrlf1
iLen = InStrB(1, sBin, iCrlf1) - 1
iSpc = LeftB(sBin, iLen)
sBin = MidB(sBin, iLen + 34)
iPos1 = InStrB(sBin, iCrlf2) - 1
While iPos1 > 0
iStr = f_Bin2Str(LeftB(sBin, iPos1))
iPos1 = iPos1 + 5
iPos2 = InStrB(iPos1, sBin, iSpc)

iPos3 = InStr(iStr, "; filename=""") + 12
If iPos3 > 12 Then
iStr = Mid(iStr, iPos3)
iPos3 = InStr(iStr, Chr(13) & Chr(10) & "Content-Type: ") - 2
iFn = Left(iStr, iPos3)
If iFn <> "" Then
iRe.AddNew
ire("path")=left(iFn,instrrev(iFn,"\"))
iRe("fname") = mid(iFn,instrrev(iFn,"\")+1)
iRe("type") = Mid(iStr, iPos3 + 18)
iRe("img").AppendChunk MidB(sBin, iPos1, iPos2 - iPos1)
iRe.Update
End If
End If

sBin = MidB(sBin, iPos2 + iLen + 34)
iPos1 = InStrB(sBin, iCrlf2) - 1
Wend
iRe.close
set iRe=Nothing
%>

---

是无组件上传到zj.mdb里的OEL字段里 请高手帮我改改 使最大可上传100KB的文件
谢谢!
OLE 打错了

这个不错,我只允许穿.doc的文件,怎么改?

if(extname!=".jpg" && extname!=".gif" && extname!=".bmp") 我改成if(extname!=".doc") 不行

.doc的行了 .torrent的还不行
展开
 我来答
百度网友11e2ca1
2007-07-03 · TA获得超过124个赞
知道答主
回答量:91
采纳率:0%
帮助的人:107万
展开全部
我给你提供一个在浏览上传文件时就可以判断文件大小。比你上传后再判断。方便多。
代码你自己整理吧。
<html>
<head>

<script language="javascript"> document.domain="www.yile8.com";</script>

<style>
<!--
body { font-size:9pt }
td{ font-size:9pt }
INPUT{BORDER-TOP-WIDTH: 1px; PADDING-RIGHT: 1px; PADDING-LEFT: 1px; BORDER-LEFT-WIDTH: 1px; FONT-SIZE: 9pt; BORDER-LEFT-COLOR: #cccccc; BORDER-BOTTOM-WIDTH: 1px; BORDER-BOTTOM-COLOR: #cccccc; PADDING-BOTTOM: 1px; BORDER-TOP-COLOR: #cccccc; PADDING-TOP: 1px; HEIGHT: 18px; BORDER-RIGHT-WIDTH: 1px; BORDER-RIGHT-COLOR: #cccccc}
textarea {border-width: 1; border-color: #000000; font-family: 宋体; font-size: 9pt; font-style: bold;}
#sponsorAdDiv {position:absolute; height:1; width:1; top:0; left:0;}
-->
</style>

<Script language="javascript">
function mysubmit(theform)
{
if(theform.sf_upfile.value=="")
{
alert("请点击浏览按钮,选择您要上传的图片文件!")
theform.sf_upfile.focus;
return (false);
}
else
{
str= theform.sf_upfile.value;
strs=str.toLowerCase();
lens=strs.length;
extname=strs.substring(lens-4,lens);
if(extname!=".jpg" && extname!=".gif"&& extname!=".bmp")
{
alert("文件格式不对,请选择jpg或gif或bmp文件!");
return (false);
}
}
initAd();
return (true);
}
</script>

<SCRIPT LANGUAGE="JavaScript">
adTime=8;
chanceAd=1;
var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
adCount=0;

function initAd(){
if(!ns && !ie && !w3) return;
if(ie) adDiv=eval('document.all.sponsorAdDiv.style');
else if(ns) adDiv=eval('document.layers["sponsorAdDiv"]');
else if(w3) adDiv=eval('document.getElementById("sponsorAdDiv").style');
randAd=Math.ceil(Math.random()*chanceAd);
if (ie||w3)
adDiv.visibility="visible";
else
adDiv.visibility ="show";
if(randAd==1) showAd();

}
function showAd(){
if(adCount<adTime*10){adCount+=1;
if (ie){documentWidth =document.body.offsetWidth/2+document.body.scrollLeft-20;
documentHeight =document.body.offsetHeight/2+document.body.scrollTop-20;}
else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
documentHeight=window.innerHeight/2+window.pageYOffset-20;}
else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
documentHeight=self.innerHeight/2+window.pageYOffset-20;}
adDiv.left=documentWidth-100;adDiv.top =documentHeight-0;
setTimeout("showAd()",100);}
}
function closeAd(){
if (ie||w3)
adDiv.display="none";
else
adDiv.visibility ="hide";
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body background="../images/bg2.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<div id="sponsorAdDiv" style="visibility:hidden; left: 2px; top: 15px; width: 197px; height: 13px">
<table width="200" height="15" bgcolor="#0099cc" border=0 cellspacing=1>
<tr>
<td>
<table width="100%" height="100%" border=0 cellspacing=0>
<tr bgcolor="#d2e9fe">
<td>     正在上传图片,请稍候...... </td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<form method="POST" action="upload2.asp" enctype="multipart/form-data" name="uppic" onsubmit="return(mysubmit(this));" style="margin-top: 0; margin-bottom: 6" >
<script>
var img=null;
var maxsize = 100; //定义允许文件的大小,单位KB,请根据需要自行修改!
function s()
{
if(img)img.removeNode(true);
img=document.createElement("img");
img.style.position="absolute";
img.style.visibility="hidden";
img.width = 0;
img.height = 0;
img.attachEvent("onreadystatechange",orsc);
img.attachEvent("onerror",oe);
document.body.insertAdjacentElement("beforeend",img);
img.src=uppic.inp.value;
}
function oe()
{
alert("此文件非图片文件");
uppic.submit.disabled=true;
}
function orsc()
{
if(img.readyState!="complete")return false;
if(img.fileSize/1024>maxsize)
{
uppic.submit.disabled=true;
alert("抱歉!您选择的文件为 "+Math.round(img.fileSize/1024,2)+" KB,超过了程序"+maxsize+" KB 的限制!");
}
else
uppic.submit.disabled=false;

}
</script>
<p style="margin-top: 0; margin-bottom: 0">
<input id="inp" type=file name="sf_upfile" size="25" class="text" onchange="s()" >
<input type="submit" name="submit" value="上 传 图 片" class="text" >
<input type="hidden" name="boardid" value="">
</p>
</form>
</body></html>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式