ASP网站大文件下载的问题
我建立的ASP网站,用文件Downloads.asp实现下载,代码如下:<%'格式:Downloads.asp?FileName=要下载的文件名DimStreamDimC...
我建立的ASP网站,用文件Downloads.asp
实现下载,代码如下:
<%
'格式:Downloads.asp?FileName=要下载的文件名
Dim Stream
Dim Contents
Dim FileName
Dim FileExt
Const adTypeBinary = 1
FileName = Request.QueryString("FileName")
if FileName = "" Then
Response.Write "无效文件名."
Response.End
End if
' 下面是不希望下载的文件
FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)
Select Case UCase(FileExt)
Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
Response.Write "受保护文件,不能下载."
Response.End
End Select
' 下载这个文件
Response.Clear
Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename=" & FileName
Set Stream = server.CreateObject("ADODB.Stream")
Stream.Type = adTypeBinary
Stream.Open
Stream.LoadFromFile Server.MapPath(FileName)
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
%>
可是实际使用中,下载4、50m以下的文件还可以,下载1、200m的文件就不灵了,这个问题有办法解决吗? 展开
实现下载,代码如下:
<%
'格式:Downloads.asp?FileName=要下载的文件名
Dim Stream
Dim Contents
Dim FileName
Dim FileExt
Const adTypeBinary = 1
FileName = Request.QueryString("FileName")
if FileName = "" Then
Response.Write "无效文件名."
Response.End
End if
' 下面是不希望下载的文件
FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)
Select Case UCase(FileExt)
Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
Response.Write "受保护文件,不能下载."
Response.End
End Select
' 下载这个文件
Response.Clear
Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename=" & FileName
Set Stream = server.CreateObject("ADODB.Stream")
Stream.Type = adTypeBinary
Stream.Open
Stream.LoadFromFile Server.MapPath(FileName)
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
%>
可是实际使用中,下载4、50m以下的文件还可以,下载1、200m的文件就不灵了,这个问题有办法解决吗? 展开
3个回答
展开全部
<%
host=Request.ServerVariables("HTTP_HOST")
fwym="http://" & host & Request.ServerVariables("SCRIPT_NAME")
wenjian=request("wenjian")
select case true
case right(lcase(wenjian),4)=".asp"
response.write "该类型文件不允许下载。"
response.end
case right(lcase(wenjian),4)=".php"
response.write "该类型文件不允许下载。"
response.end
case right(lcase(wenjian),5)=".aspx"
response.write "该类型文件不允许下载。"
response.end
end select
wenjian=replace(wenjian,"/","\")
a=split(wenjian,"\")
filename=a(ubound(a))
Set fso = CreateObject("Scripting.FileSystemObject")
fileurl=left(fwym,len(fwym)-8) & wenjian
fileurl=replace(fileurl,"\","/")
if instr(1,wenjian,":")=0 then wenjian=server.mappath(wenjian)
'设置可下载文件大小上限
maxsize=50000000
'response.write wenjian
'response.end
set f1=fso.getfile(wenjian)
if f1.size>maxsize then
response.write "文件太大了,不允许下载。" & dxzh(f1.size) & "只支持" & dxzh(maxsize) & "以内的文件下载"
response.end
end if
if instr(1,wenjian,":")=0 then
'response.write fileurl
response.redirect fileurl
response.end
end if
Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename =" & filename
set objstream = Server.CreateObject("adodb.stream")
objstream.Mode = 3
objstream.Type = 1
objstream.Open
objstream.LoadFromFile (wenjian)
BytesToBstr = objstream.Read
response.binarywrite BytesToBstr
function dxzh(dx)
zijieshu = dx & "字节"
kbshu = FormatNumber(dx / 1024, "0.0") & "KB"
mbshu = FormatNumber(dx / 1024 / 1024, 2) & "MB"
fsize = dx
If fsize / 1024 < 1 Then dxzh = zijieshu
If fsize / 1024 >= 1 And fsize / 1024 < 1024 Then dxzh = kbshu
If fsize / 1024 >= 1024 Then dxzh = mbshu
end function
%>
host=Request.ServerVariables("HTTP_HOST")
fwym="http://" & host & Request.ServerVariables("SCRIPT_NAME")
wenjian=request("wenjian")
select case true
case right(lcase(wenjian),4)=".asp"
response.write "该类型文件不允许下载。"
response.end
case right(lcase(wenjian),4)=".php"
response.write "该类型文件不允许下载。"
response.end
case right(lcase(wenjian),5)=".aspx"
response.write "该类型文件不允许下载。"
response.end
end select
wenjian=replace(wenjian,"/","\")
a=split(wenjian,"\")
filename=a(ubound(a))
Set fso = CreateObject("Scripting.FileSystemObject")
fileurl=left(fwym,len(fwym)-8) & wenjian
fileurl=replace(fileurl,"\","/")
if instr(1,wenjian,":")=0 then wenjian=server.mappath(wenjian)
'设置可下载文件大小上限
maxsize=50000000
'response.write wenjian
'response.end
set f1=fso.getfile(wenjian)
if f1.size>maxsize then
response.write "文件太大了,不允许下载。" & dxzh(f1.size) & "只支持" & dxzh(maxsize) & "以内的文件下载"
response.end
end if
if instr(1,wenjian,":")=0 then
'response.write fileurl
response.redirect fileurl
response.end
end if
Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename =" & filename
set objstream = Server.CreateObject("adodb.stream")
objstream.Mode = 3
objstream.Type = 1
objstream.Open
objstream.LoadFromFile (wenjian)
BytesToBstr = objstream.Read
response.binarywrite BytesToBstr
function dxzh(dx)
zijieshu = dx & "字节"
kbshu = FormatNumber(dx / 1024, "0.0") & "KB"
mbshu = FormatNumber(dx / 1024 / 1024, 2) & "MB"
fsize = dx
If fsize / 1024 < 1 Then dxzh = zijieshu
If fsize / 1024 >= 1 And fsize / 1024 < 1024 Then dxzh = kbshu
If fsize / 1024 >= 1024 Then dxzh = mbshu
end function
%>
展开全部
这个问题应该去CSDN问或者javaeye 算了我告诉你吧 在你asp.net
程序的webconfig文件里的
<system.web> 这个节点
<httpRuntime maxRequestLength="204800" executionTimeout="30000"/>
加上这句话 1024表示一M 你自己算下
出于安全限制iis和asp都不允许下载大数据文件
程序的webconfig文件里的
<system.web> 这个节点
<httpRuntime maxRequestLength="204800" executionTimeout="30000"/>
加上这句话 1024表示一M 你自己算下
出于安全限制iis和asp都不允许下载大数据文件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
IIS网站属性里脚本运行超时的时间,调节下就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询