NEWS

分享创造价值   合作实现共赢

上传大文件到服务器报错的处理方法

一直用无惧上传类,这是一个非常简单且优秀的asp无组件上传类,但有一次有客户上传超过1m的文件时传不上去,所以就仔细的研究了下其代码,报错的原因是一次性上传的文件太大导致报错,如果程序将文件分成若干个板块再上传就不会报错

打开无惧上传类:upfile_class.asp,定位到120行:

oupfilestream.write request.binaryread (request.totalbytes)(用单引号注释掉或者删除掉这一句代码)回车,加以下代码:

Dim nTotalBytes, nPartBytes, ReadBytes
ReadBytes = 0
nTotalBytes = Request.TotalBytes
'循环分块读取
Do While ReadBytes < nTotalBytes
'分块读取
nPartBytes = 64 x 1024 '分成每块64k(将x换成星号)
If nPartBytes + ReadBytes > nTotalBytes Then
nPartBytes = nTotalBytes - ReadBytes
End If
oUpFileStream.Write Request.BinaryRead(nPartBytes)
ReadBytes = ReadBytes + nPartBytes
Loop

保存在oupfilestream.position = 0这行代码之上,现在测试下是不是好了?

相关文章