标题:
IIS6 中ASP上传文件大小限制为200K的问题
[打印本页]
作者:
chinanic
时间:
2007-1-28 10:23
标题:
IIS6 中ASP上传文件大小限制为200K的问题
这两天研究ASP上传。发现一提交大于200K的数据就会[color=#FF0033] 500错误,我汗S。。在网上找了很久,都是通过[color=#FF0033]修改IIS配置解决的。。
我想通过自己写个函数来实现。求思路~!
作者:
netskill
时间:
2007-1-29 07:07
标题:
IIS6 中ASP上传文件大小限制为200K的问题
修改了 也没用
不如换上传组建
作者:
chinanic
时间:
2007-1-29 14:27
标题:
IIS6 中ASP上传文件大小限制为200K的问题
晕。偶是要换自己写的组件。。就是不知道怎样写。。所以来讨下经验。。
作者:
chinanic
时间:
2007-1-30 07:10
标题:
IIS6 中ASP上传文件大小限制为200K的问题
发现可以用ADODB.Stream对象分块读取,只要每次读的字节数小于200K就行了。
但郁闷的是得到的数据仅限头部那一点点,我晕。。。
继续研究中。。
作者:
chinanic
时间:
2007-1-30 20:06
标题:
IIS6 中ASP上传文件大小限制为200K的问题
[这个贴子最后由chinanic在 2007/01/30 08:09pm 第 1 次编辑] ·今天用ADODB.Stream实现了数据分块读取,哈哈。。可以传200K以上的文件啦。。 ·下一步要实现的是文件数据的提取。。嗯,就是分析那堆乱码啦。。 ·以下代码实现大文件上传,仅供参考。。 ·另ADODB.Stream貌似消耗服务器资源的说。。希望朋友们帮想一下其它办法。 :14:
<%
Dim ReadBytes,ToRead,Err_Code
ReadBytes=0
ToRead = 200000
Set objStream=Server.CreateObject("ADODB.Stream")
';指定返回数据类型 adTypeBinary=1,adTypeText=2
objStream.Type=1
';指定打开模式 adModeRead=1,adModeWrite=2,adModeReadWrite=3
objStream.Mode=3
objStream.Open
binBytes=Request.TotalBytes
';以下两句用来显示提交数据长度
Response.write "<br>"
Response.write binBytes
if binBytes=0 then
';错误输出:没有上传任何数据
Err_Code=0
Response.End
End if
';循环读取提交的数据
Do while ReadBytes < binBytes
';提交的数据或最后一次所取数据可能不足200K,加个判断即可取得精确数据长度
if ToRead > binBytes-Readbytes then
ToRead=binBytes-Readbytes
end if
objStream.Write Request.BinaryRead(Toread)
Readbytes=Readbytes+ToRead
Loop
objStream.Position=0
objStream.Type=1
';建立输出对象
Set outStream=Server.CreateObject("ADODB.Stream")
outStream.Type=1
outStream.Open
objStream.CopyTo outStream
';设置输出对象的指针位置
outStream.Position=0
outStream.Type=2
';读取对象内容,存入变量
strItem=outStream.ReadText
Response.binarywrite strItem
';关闭对象
outStream.close
objStream.close
%>
复制代码
作者:
chinanic
时间:
2007-1-30 21:16
标题:
IIS6 中ASP上传文件大小限制为200K的问题
通过分析文件头数据,得到文件本地路径,文件名,扩展名,文件类型,表单域名称。并以原文件名将文件保存到服务器。
<%
Dim ReadBytes,ToRead,Err_Code,strFileData,strUpLoadData
Dim bCrLf,strSeparator,intSeparator
Dim File_start,File_end,File_SavePath,strItem,strItemName,intTemp,strTemp
Dim strFileType,strFileName,strFileExt,LngFilesize
File_SavePath=""
';回车换行符的二进制数据
bCrLf=ChrB(13)&ChrB(10)
ReadBytes=0
ToRead = 200000
';建立对象
Set objStream=Server.CreateObject("ADODB.Stream")
Set binItem=Server.CreateObject("ADODB.Stream")
';指定返回数据类型 adTypeBinary=1,adTypeText=2
objStream.Type=1
';指定打开模式 adModeRead=1,adModeWrite=2,adModeReadWrite=3
objStream.Mode=3
objStream.Open
binBytes=Request.TotalBytes
if binBytes=0 then
';错误输出:没有上传任何数据
Err_Code=0
Response.End
End if
';判断提交的数据是否超过限制,如果没有则按原大小读取
Do while ReadBytes < binBytes
';提交的数据或最后一次所取数据可能不足200K,加个判断即可取得精确数据长度
if ToRead > binBytes-Readbytes then
ToRead=binBytes-Readbytes
end if
objStream.Write Request.BinaryRead(Toread)
Readbytes=Readbytes+ToRead
Loop
';设置对象指针位置
objStream.Position=0
objStream.Type=2
strUpLoadData=objStream.ReadText
';取得分界符的长度
intSeparator=InstrB(1,strUpLoadData,bCrLf)-1
';取得分界符
strSeparator=LeftB(strUpLoadData,intSeparator)
';数据块开始位置=分界符长度加上1个回车符,再加上一个文件块的首字符
File_start=intSeparator+2
';在两个回车符处结束,获得数据头部信息
File_end =InStrB(File_start,strUpLoadData,bCrLf&bCrLf)+3
';指定binItem对象返回的数据为二进制
binItem.Type=1
';打开对象
binItem.Open
';设置objStream对象当前指针位置
objStream.Position=File_start
';将objStream中的第一段数据复制入binItem中
objStream.CopyTo binItem,File_end-File_start
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strItem=binItem.ReadText
binItem.Close()
';下一段数据开始位置
File_start=File_end
';下一块的结束位置,注意要减去一个分界符位
File_end=InStrB(File_start,strUpLoadData,strSeparator)-1
binItem.Type=1
binItem.Open
';重置objStream指针位置
objStream.Position=File_start
';数据块长度
LngFilesize=File_end-File_start-2
';将文件数据拷入binItem
objStream.CopyTo binItem,LngFilesize
';以上暂缓
';下面进行头部分析工作
';39是“Content-Disposition: form-data; name="”的长度,在此后面找到的第一个双引号为表单域名结束
intTemp=Instr(39,strItem,"""")
';取得表单域名
strItemName=Mid(strItem,39,intTemp-39)
';从表单域名后开始查找文件名
if Instr(intTemp,strItem,"filename=""")<>0 then
intTemp=intTemp+13
';获取文件类型即第一块中“Content-Type: ”的位置+14
strFileType=Mid(strItem,Instr(intTemp,strItem,"Content-Type: ")+14)
';得到文件完整源路径
strTemp=Mid(strItem,intTemp,Instr(intTemp,strItem,"""")-intTemp)
intTemp=InstrRev(strTemp,"\")
';得到文件名
strFileName=Mid(strTemp,intTemp+1)
End if
';取得文件扩展名
if Instr(intTemp,strTemp,".")<>0 then
strFileExt=Mid(strTemp,InstrRev(strTemp,".")+1)
else
strFileExt=""
end if
Response.Write "源路径:" & strTemp
Response.Write "<br>文件名:" & strFileName
Response.Write "<br>扩展名:" & strFileExt
Response.Write "<br>文件类型:" & strFileType
Response.Write "<br>文件大小:" & LngFileSize &"字节"
Response.Write "<br>表单域名:" & strItemName
';储存文件
binItem.SaveToFile Server.MapPath(File_SavePath&strFileName)
binItem.close
objStream.close
%>
复制代码
以上代码仅实现了单个大文件的上传。其它功能有待扩充。。谢谢关注~!
作者:
netskill
时间:
2007-2-1 09:52
标题:
IIS6 中ASP上传文件大小限制为200K的问题
麻烦内
作者:
chinanic
时间:
2007-2-1 17:54
标题:
IIS6 中ASP上传文件大小限制为200K的问题
做东西就这样啊。。
我们麻烦就是为了方便更多的人嘛。。
咳。。表吐。。
欢迎光临 黑色海岸线论坛 (http://bbs.thysea.com/)
Powered by Discuz! 7.2