| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2389 人关注过本帖
标题:[请教]控制上传文件大小问题
只看楼主 加入收藏
craft001wen
Rank: 2
等 级:论坛游民
帖 子:242
专家分:62
注 册:2006-5-4
收藏
 问题点数:0 回复次数:10 
[请教]控制上传文件大小问题

我的代码如下:
<%'
dim upfile,formPath,ServerPath,FSPath,formName,FileName,oFile,upfilecount,newfilename
set upfile=new clsUp ''建立上传对象
upfile.NoAllowExt="asp;exe;htm;html;aspx;cs;vb;js;" '设置上传类型的黑名单
upfile.GetDate (5024000) '取得上传数据,限制最大上传5M
%>

我限制的是5M但是只能最大上传100K,这也相差太远了!
哪位高手,指点一下。谢谢!


<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body leftmargin="0" topmargin="0">
<%
if upfile.isErr then '如果出错
select case upfile.isErr
case 1
Response.Write "你没有上传数据呀!是不是搞错了!"
case 2
Response.Write "你上传的文件超出我们的限制,最大1M"
end select
else
%>

<%
FSPath=GetFilePath(Server.mappath("uploadfile.asp"),"\")'取得当前文件在服务器路径
FSPath=FSPath&"uploadfile\"
'response.Write(fspath)
'response.End()
'FSPath="uploadfile/"
ServerPath=GetFilePath(Request.ServerVariables("HTTP_REFERER"),"/")'取得在网站上的位置
'response.Write(ServerPath)
'response.End()
for each formName in upfile.file '列出所有上传了的文件
set oFile=upfile.file(formname)
FileName=upfile.form(formName)'取得文本域的值
if not FileName>"" then FileName=oFile.filename'如果没有输入新的文件名,就用原来的文件名
'upfile.SaveToFile formname,FSPath&FileName ''保存文件 也可以使用AutoSave来保存,参数一样,但是会自动建立新的文件名
'upfile.autosave formname,FSPath&FileName
newFileName=upfile.autosave(formname,FSPath&FileName)

%>
 <!--<A HREF="<%'=serverpath&"uploadfile/"&newFileName%>"><%'=newFileName%></A> --->
 <%
if upfile.iserr then
Response.Write upfile.errmessage
else
if request.QueryString("parm")<>"" then
response.Write "<script language='javascript'>parent.myform."&request.QueryString("parm")&".value='uploadfile/"&newFileName&"';</script>"
end if
upfilecount=upfilecount+1
Response.Write "上传成功&nbsp;"
response.Write(""&serverpath&"uploadfile/"&newFileName)
end if
%> 
<%
set oFile=nothing
next
%>

<%
end if
set upfile=nothing '删除此对象
%>

<!-- [<a href="uploadfilewithparm.asp">返回</a>] -->


</body>
</html>

<%
function GetFilePath(FullPath,str)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, str))
Else
GetFilePath = ""
End If
End function
%>

搜索更多相关主题的帖子: 文件 upfile title 
2006-05-23 14:48
piaoxue
Rank: 3Rank: 3
来 自:地球
等 级:论坛游侠
威 望:3
帖 子:606
专家分:113
注 册:2005-9-19
收藏
得分:0 
应该还有一个文件吧!  这个上面没有限制上传的哪个语句呀!???!

我是做平面设计、网站制作、网站推广、主机域名等业务的站长。有需要的给我站内信吧。
2006-05-23 14:59
程序错误
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2006-4-30
收藏
得分:0 
filesize获取文件的大小,然后进行比较

天因你而更蔚蓝~~~~~~
地狱因我而黑暗~~~~~~
2006-05-23 15:08
craft001wen
Rank: 2
等 级:论坛游民
帖 子:242
专家分:62
注 册:2006-5-4
收藏
得分:0 

上传对像的文件是 clsup,我找了很久,也没看到限制的语句,帮我改一下,谢谢!
clsup.asp代码:

<%
'--------------------------------------------------------------------------------------------
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'******************* 先锋无组件上传类(杜绝上传漏洞版) Ver2004 ********************
'作者:梁无惧、孙立宇、apollosun、ezhonghua
'官方网站:http://www.lkstar.com 技术支持论坛:http://bbs.lkstar.com
'电子邮件:kickball@netease.com 在线QQ:94294089
'版权声明:版权没有,盗版不究,源码公开,各种用途均可免费使用,欢迎你到技术论坛来寻求支持。
'网上流行的所有的无组件上传类都有该类漏洞——黑客利用抓包嗅探、ULTRAEDIT和“网络军刀”
'等黑客工具伪造IP包,可以突破服务器端对上传文件名、路径的判断,从而巧妙上传ASP、ASA、CGI、CDX、
'CER、ASPX类型的网页木马。本人仔细分析了各种黑客手段,针对网上最流行的无惧上传类进行修改,
'在写入服务端的最后关键使黑客的如意算盘付之东流.目前提供的这个类完全堵上了上传漏洞,请放心使用!
'详细使用说明或范例请见下载附件或到本人官方站点下载!
'---------------------------------------------------------------------------------------------
class clsUp '文件上传类
'------------------------
Dim Form,File
Dim AllowExt_ '允许上传类型(白名单)
Dim NoAllowExt_ '不允许上传类型(黑名单)
Private oUpFileStream '上传的数据流
Private isErr_ '错误的代码,0或true表示无错
Private ErrMessage_ '错误的字符串信息
Private isGetData_ '指示是否已执行过GETDATA过程

'------------------------------------------------------------------
'类的属性
Public Property Get Version
Version="先锋上传类(无惧类改进安全版) Version 2004"
End Property

Public Property Get isErr '错误的代码,0或true表示无错
isErr=isErr_
End Property

Public Property Get ErrMessage '错误的字符串信息
ErrMessage=ErrMessage_
End Property

Public Property Get AllowExt '允许上传类型(白名单)
AllowExt=AllowExt_
End Property

Public Property Let AllowExt(Value) '允许上传类型(白名单)
AllowExt_=LCase(Value)
End Property

Public Property Get NoAllowExt '不允许上传类型(黑名单)
NoAllowExt=NoAllowExt_
End Property

Public Property Let NoAllowExt(Value) '不允许上传类型(黑名单)
NoAllowExt_=LCase(Value)
End Property

'----------------------------------------------------------------
'类实现代码

'初始化类
Private Sub Class_Initialize
isErr_ = 0
NoAllowExt="" '黑名单,可以在这里预设不可上传的文件类型,以文件的后缀名来判断,不分大小写,每个每缀名用;号分开,如果黑名单为空,则判断白名单
NoAllowExt=LCase(NoAllowExt)
AllowExt="" '白名单,可以在这里预设可上传的文件类型,以文件的后缀名来判断,不分大小写,每个后缀名用;号分开
AllowExt=LCase(AllowExt)
isGetData_=false
End Sub

'类结束
Private Sub Class_Terminate
on error Resume Next
'清除变量及对像
Form.RemoveAll
Set Form = Nothing
File.RemoveAll
Set File = Nothing
oUpFileStream.Close
Set oUpFileStream = Nothing
End Sub

'分析上传的数据
Public Sub GetData (MaxSize)
'定义变量
on error Resume Next
if isGetData_=false then
Dim RequestBinDate,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
Dim sFormValue,sFileName
Dim iFindStart,iFindEnd
Dim iFormStart,iFormEnd,sFormName
'代码开始
If Request.TotalBytes < 300 Then '如果没有数据上传
isErr_ = 1
ErrMessage_="没有数据上传"
Exit Sub
End If
If MaxSize > 0 Then '如果限制大小
If Request.TotalBytes > MaxSize Then
isErr_ = 2 '如果上传的数据超出限制大小
ErrMessage_="上传的数据超出限制大小"
Exit Sub
End If
End If
Set Form = Server.CreateObject ("Scripting.Dictionary")
Form.CompareMode = 1
Set File = Server.CreateObject ("Scripting.Dictionary")
File.CompareMode = 1
Set tStream = Server.CreateObject ("ADODB.Stream")
Set oUpFileStream = Server.CreateObject ("ADODB.Stream")
oUpFileStream.Type = 1
oUpFileStream.Mode = 3
oUpFileStream.Open
oUpFileStream.Write Request.BinaryRead (Request.TotalBytes)
oUpFileStream.Position = 0
RequestBinDate = oUpFileStream.Read
iFormEnd = oUpFileStream.Size
bCrLf = ChrB (13) & ChrB (10)
'取得每个项目之间的分隔符
sSpace = MidB (RequestBinDate,1, InStrB (1,RequestBinDate,bCrLf)-1)
iStart = LenB(sSpace)
iFormStart = iStart+2
'分解项目
Do
iInfoEnd = InStrB (iFormStart,RequestBinDate,bCrLf & bCrLf)+3
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iFormStart
oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.CharSet = "gb2312"
sInfo = tStream.ReadText
'取得表单项目名称
iFormStart = InStrB (iInfoEnd,RequestBinDate,sSpace)-1
iFindStart = InStr (22,sInfo,"name=""",1)+6
iFindEnd = InStr (iFindStart,sInfo,"""",1)
sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
'如果是文件
If InStr (45,sInfo,"filename=""",1) > 0 Then
Set oFileInfo = new clsFileInfo
'取得文件属性
iFindStart = InStr (iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr (iFindStart,sInfo,""""&vbCrLf,1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileName = GetFileName(sFileName)
oFileInfo.FilePath = GetFilePath(sFileName)
oFileInfo.FileExt = GetFileExt(sFileName)
iFindStart = InStr (iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr (iFindStart,sInfo,vbCr)
oFileInfo.FileMIME = Mid(sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileStart = iInfoEnd
oFileInfo.FileSize = iFormStart -iInfoEnd -2
oFileInfo.FormName = sFormName
file.add sFormName,oFileInfo
else
'如果是表单项目
tStream.Close
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iInfoEnd
oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2
tStream.Position = 0
tStream.Type = 2
tStream.CharSet = "gb2312"
sFormValue = tStream.ReadText
If Form.Exists (sFormName) Then
Form (sFormName) = Form (sFormName) & ", " & sFormValue
else
Form.Add sFormName,sFormValue
End If
End If
tStream.Close
iFormStart = iFormStart+iStart+2
'如果到文件尾了就退出
Loop Until (iFormStart+2) >= iFormEnd
RequestBinDate = ""
Set tStream = Nothing
isGetData_=true
end if
End Sub

'保存到文件,自动覆盖已存在的同名文件
Public Function SaveToFile(Item,Path)
SaveToFile=SaveToFileEx(Item,Path,True)
End Function

'保存到文件,自动设置文件名
Public Function AutoSave(Item,Path)
AutoSave=SaveToFileEx(Item,Path,false)
End Function

'保存到文件,OVER为真时,自动覆盖已存在的同名文件,否则自动把文件改名保存
Private Function SaveToFileEx(Item,Path,Over)
On Error Resume Next
Dim oFileStream
Dim tmpPath
Dim nohack '防黑缓冲
isErr=0
Set oFileStream = CreateObject ("ADODB.Stream")
oFileStream.Type = 1
oFileStream.Mode = 3
oFileStream.Open
oUpFileStream.Position = File(Item).FileStart
oUpFileStream.CopyTo oFileStream,File(Item).FileSize
nohack=split(path,".") '重要修改,防止黑客二进制"01"断名!!!
tmpPath=nohack(0)&"."&nohack(ubound(nohack)) '重要修改,防止黑客二进制"01"断名!!!
if Over then
if isAllowExt(GetFileExt(tmpPath)) then
oFileStream.SaveToFile tmpPath,2
Else
isErr_=3
ErrMessage_="该后缀名的文件不允许上传!"
End if
Else
Path=GetFilePath(Path)
if isAllowExt(File(Item).FileExt) then
do
Err.Clear()
nohack=split(Path&GetNewFileName()&"."&File(Item).FileExt,".") '重要修改,防止黑客二进制"01"断名!!!
tmpPath=nohack(0)&"."&nohack(ubound(nohack)) '重要修改,防止黑客二进制"01"断名!!!
oFileStream.SaveToFile tmpPath
loop Until Err.number<1
oFileStream.SaveToFile Path
Else
isErr_=3
ErrMessage_="该后缀名的文件不允许上传!"
End if
End if
oFileStream.Close
Set oFileStream = Nothing
if isErr_=3 then SaveToFileEx="" else SaveToFileEx=GetFileName(tmpPath)
End Function

'取得文件数据
Public Function FileData(Item)
isErr_=0
if isAllowExt(File(Item).FileExt) then
oUpFileStream.Position = File(Item).FileStart
FileData = oUpFileStream.Read (File(Item).FileSize)
Else
isErr_=3
ErrMessage_="该后缀名的文件不允许上传!"
FileData=""
End if
End Function


'取得文件路径
Public function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = Left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function

'取得文件名
Public Function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function

'取得文件的后缀名
Public Function GetFileExt(FullPath)
If FullPath <> "" Then
GetFileExt = LCase(Mid(FullPath,InStrRev(FullPath, ".")+1))
Else
GetFileExt = ""
End If
End function

'取得一个不重复的序号
Public Function GetNewFileName()
dim ranNum
dim dtNow
dtNow=Now()
ranNum=int(90000*rnd)+10000
GetNewFileName=year(dtNow) & right("0" & month(dtNow),2) & right("0" & day(dtNow),2) & right("0" & hour(dtNow),2) & right("0" & minute(dtNow),2) & right("0" & second(dtNow),2) & ranNum
End Function

Public Function isAllowExt(Ext)
if NoAllowExt="" then
isAllowExt=cbool(InStr(1,";"&AllowExt&";",LCase(";"&Ext&";")))
else
isAllowExt=not CBool(InStr(1,";"&NoAllowExt&";",LCase(";"&Ext&";")))
end if
End Function
End Class
'----------------------------------------------------------------------------------------------------
'文件属性类
Class clsFileInfo
Dim FormName,FileName,FilePath,FileSize,FileMIME,FileStart,FileExt
End Class
%>


2006-05-23 15:23
craft001wen
Rank: 2
等 级:论坛游民
帖 子:242
专家分:62
注 册:2006-5-4
收藏
得分:0 
用file.filesize时,提示不支持该属性!

2006-05-23 16:06
icecool
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:20
帖 子:1215
专家分:1376
注 册:2005-3-14
收藏
得分:0 

fsize=request.totalbytes

用这个试试,误差好像很小.

fsize=request.totalbytes
if act="up" then
maxsize=fsize /1024
if maxsize > 50 then
response.write "上传文件不能超过50K"
response.end
else
uploading(file)
end if


http://toorup.3v.do
loading...
2006-05-24 09:59
craft001wen
Rank: 2
等 级:论坛游民
帖 子:242
专家分:62
注 册:2006-5-4
收藏
得分:0 

这个我也试过了,我用的产无惧上传 类,好像文件大小的控制,只对200K以下的有用。
而200K,以上的文件,上传都提示出错!
我在网上,查了一下,好像很少有上传单个文件超过200K的类,还说是IIS默认,只能上传200K。我去找了一下,没找到在哪设置?不知道谁会的,帮帮忙,我现在有一个文件,有9M,没法上传!


2006-05-24 17:49
icecool
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:20
帖 子:1215
专家分:1376
注 册:2005-3-14
收藏
得分:0 

如何解除FSO上传程序小于200k限制?

以下内容别的地方找的,没试过,你可试试看


如何解除FSO上传程序小于200k限制?bbs.1teng.com*UAr1Kjh]v$|M
| xU4e7y%i
  先在服务里关闭IISadminservice服务,找到Windows\System32\Inesrv目录下的Metabase.xml并打开,找到ASPMaxRequestEntityAllowed,将其修改为需要的值。默认为204800,即200K,把它修改为51200000(50M),然后重启IISadminservice服务。 win服务器,代理服务器,邮件服务器,代码,程序,游戏下载,软件,电脑技术,设计,图片,信息发布Z@#Ncu$gs
  开启与关闭win2003企业版中FSO组件
r1NZkEf  1、首先在系统盘中查找scrrun.dll,如果存在这个文件,请跳到第三步,如果没有,请执行第二步。中国服务器论坛联盟 1c9M&P
spl!}-fX


:\R1PY/Y  2、在安装文件目录i386中找到scrrun.dl_,用winrar解压缩,得scrrun.dll,然后复制到x(你的系统盘):\windows\system32\目录中。
,}[
Kky;q Z;z Tbbs.1teng.com5E_:V9oP"KC1X
  3、运行regsvr32scrrun.dll即可。
g3v:NZ.g@中国服务器论坛联盟 S Sva+NS
  4、如果想关闭FSO组件,请运行regsvr32/uscrrun.dll即可。


http://toorup.3v.do
loading...
2006-05-24 17:57
craft001wen
Rank: 2
等 级:论坛游民
帖 子:242
专家分:62
注 册:2006-5-4
收藏
得分:0 
先谢过了,我试试先!

2006-05-24 18:06
craft001wen
Rank: 2
等 级:论坛游民
帖 子:242
专家分:62
注 册:2006-5-4
收藏
得分:0 

谢谢icecool,问题果然是这,改了之后,可以上传大文件了


2006-05-26 08:20
快速回复:[请教]控制上传文件大小问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012644 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved