|
蓝森林 http://www.lslnet.com 2006年8月25日 8:28
(asp上传问题)如何更改呢?
下面的这个上传文件只能限制一次上传的总大小,我该怎样改成限制每个上传文件不能大于多少?
---------------
<!--#include file="conn.asp" -->
<!--#include file="checkuser.asp" -->
<!--#INCLUDE FILE="upload.inc"-->
<!--#include file="Config.asp"-->
<%title=request("title")%>
<%folderid=request("folderid")%>
<%
function lngConvert2(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
lngConvert2 = clng(ascb(str2) + ((ascb(str1) * 256)))
end function
function lngConvert(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
len1=ascb(str1)
len2=ascb(str2)
lngConvert = clng(ascb(str1) + ascb(str2) * 256)
end function
Dim FormData,FormSize
FormSize=Request.TotalBytes
FormData=Request.BinaryRead(FormSize)
Set Fields = GetUpload(FormData)
If formsize = 0 or Formsize > OKsize Then
UploadSize=False
Response.Write"<script>alert('你要上传的照片大小超出程序限制(一次上传不能大于1M)!');history.back();</script>"
Response.End
End If
for i=1 to 10 '获得图片的宽度和高度
If Fields("file"&i).FileName<>"" and Fields("file"&i).value<>"" Then
tempstr=Leftb(Fields("file"&i).Value,10)
tstr=chrb(255)&chrb(216)&chrb(255)&chrb(224)&chrb(0)&chrb(16)&chrb(74)&chrb(70)&chrb(73)&chrb(70)
flag=1
if strcomp(tempstr,tstr,0)=0 then
lngSize = len(fields("file"&i).value)
flgFound = 0
strTarget = chrb(255) & chrb(216) & chrb(255) 'JPG
flgFound = instrb(fields("file"&i).value, strTarget)
if flgFound = 0 then
response.write "<br><br><br><br><p align=center>照片上传有可能错误!是否继续上传?<br><Br>(照片也许没有经过处理)<br><br><br>"
response.write "<a href='addphoto.asp?way=back' title='继续上传'><font color='#000000'>是</font></a><font color='#FFFFFF'>照片上传</font><a href='myphoto.asp?way=back' title='返回照片管理'><font color='#000000'>否</font></a>"
response.end
end if
strImageType = "JPG"
lngPos = flgFound + 2
ExitLoop = false
do while ExitLoop = False and lngPos < lngSize
do while ascb(midb(fields("file"&i).value, lngPos, 1)) = 255 and lngPos < lngSize
lngPos = lngPos + 1
loop
if ascb(midb(fields("file"&i).value, lngPos, 1)) < 192 or ascb(midb(fields("file"&i).value, lngPos, 1)) > 195 then
lngMarkerSize = lngConvert2(midb(fields("file"&i).value, lngPos + 1, 2))
lngPos = lngPos + lngMarkerSize + 1
else
ExitLoop = True
end if
loop
height = lngConvert2(midb(fields("file"&i).value, lngPos +4, 2))
width = lngConvert2(midb(fields("file"&i).value, lngPos +6, 2))
flag=2
else
flag=0
end if
if flag<>2 then
tempstr=Leftb(Fields("file"&i).Value,6)
tstr=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(57)&chrb(97)
tstr2=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(55)&chrb(97)
if strcomp(tempstr,tstr,0)=0 or strcomp(tempstr,tstr2)=0 then
width=lngConvert(midb(fields("file"&i).value,7,2))
height=lngConvert(midb(fields("file"&i).value,9,2))
flag=2
else
flag=0
end if
end if
if flag>0 then
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from pic"
rs.open sql,conn,1,3
fieldsdata=Array("title","intro","date","ssort","username","mi","kb","width","height","url")
valuesdata=Array(Fields("title").Value,Fields("intro").Value,now,Fields("ssort").value,Fields("username").value,Fields("mi").value,formsize,width,height,"")
rs.addnew fieldsdata,valuesdata
set field=rs.fields("url")
field.appendchunk Fields("file"&i).Value
ttt=replace(Fields("file"&i).Value,"'","''")
Rs.Update
rs.close
set rs=nothing
else
response.write "<script>alert('图像不符合要求,上传失败!');this.location.href='addphoto.asp?way=back';</script>"
response.End()
end if
else
end if
next
sql3="select * from pic where url=''"
set rs3=server.CreateObject("adodb.recordset")
rs3.open sql3,conn,1,3
if (not rs3.eof) or (not rs3.bof) then
conn.execute("delete * from pic where url=''")
end if
rs3.close
set rs3=nothing
response.write "<script>alert(""上传成功!"");location.href=""contain.asp?title="&title&"&folderid="&folderid&"&way=back"";</script>"
response.end
connclose%> |
|