我将.exe、.doc、.zip、.ppt、.exl等文件以2进制格式放在数据库中,现在要用asp文件将它们取出来并且点击下载到客户端(必须自动辨认正确的文件扩展名),比如一编msword的文档,我用Response.ContentType="application/msword"
Response.BinaryWrite rs("file").getChunk(rs("file").ActualSize)将它取出并下载或打开。
现在的问题是碰到exe、.zip、.ppt等文件应该怎么办,有什么办法,请赐教。
---------------------------------------------------------------
辨认扩展名好办,存进数据库时把文件名也保存
-----------------------------
千年精灵( Millennium Genius )
---------------------------------------------------------------
用流(stream)输出
-----------------------------
千年精灵( Millennium Genius )
---------------------------------------------------------------
function dl(f,n)
on error resume next
Set S=CreateObject("Adodb.Stream")
S.Mode=3
S.Type=1
S.Open
S.LoadFromFile(f)
if Err.Number>0 then
Response.Status="404"
else
Response.ContentType="application/octet-stream"
Response.AddHeader "Content-Disposition:","attachment; filename=" & n
Range=Mid(Request.ServerVariables("HTTP_RANGE"),7)
if Range="" then
Response.BinaryWrite(S.Read)
else
S.position=Clng(Split(Range,"-")(0))
Response.BinaryWrite(S.Read)
End if
end if
Response.End
end function
函数使用示例:
call dl(Server.MapPath("../download/07.zip"),"07.zip")
-----------------------------
千年精灵( Millennium Genius )
---------------------------------------------------------------
不能直接传的