急!asp用stream直接下载文件的问题

kookies 2006-04-12 10:04:45
能够弹出文件下载对话框。可是为什么下载文件的大小才5k?原文件可是5M多呢:(
在我的机器上下载正常,放到外部服务器就只有5k。
...全文
209 4 打赏 收藏 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kookies 2006-04-13
  • 打赏
  • 举报
回复
自己顶一下
kookies 2006-04-12
  • 打赏
  • 举报
回复
我的代码:
Function downloadFile(strFile)
'' make sure you are on the latest MDAC version for this to work
'' get full path of specified file
strFilename = server.MapPath(strFile)

'' clear the buffer
Response.Buffer = True
Response.Clear

'' create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open

'' Set as binary
s.Type = 1

'' load in the file
on error resume next

'' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>"&strFilename&" does not exists!<p>")
Response.End
end if

'' get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size

s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>Unknown Error!<p>")
Response.End
end if

'' send the headers to the users Browse
Response.AddHeader "Content-Disposition","attachment; filename="&f.name
Response.AddHeader "Content-Length",intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"

'' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush

'' tidy up
s.Close
Set s = Nothing

End Function
sxsgssgs 2006-04-12
  • 打赏
  • 举报
回复
用这个试试。

<%
'===================================
'下载文件
'===================================
Function downloadFile(strFile)
' make sure you are on the latest MDAC version for this to work
' get full path of specified file
strFilename = server.MapPath(strFile)

' clear the buffer
Response.Buffer = True
Response.Clear

' create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open

' Set as binary
s.Type = 1

' load in the file
on error resume next

' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>"&strFilename&" does not exists!<p>")
Response.End
end if

' get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size

s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>Unknown Error!<p>")
Response.End
end if

' send the headers to the users Browse
Response.AddHeader "Content-Disposition","attachment; filename="&f.name
Response.AddHeader "Content-Length",intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"

' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush

' tidy up
s.Close
Set s = Nothing

End Function
downloadFile(strfile) 'strfile为相对路径。
%>

28,402

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧