wenku.sharew.cn
ASP实现文件下载,保存文件名中文不会乱码
浏览:3 | 发布时间:2018-1-19 22:14:09

'**使用方法:在点击下载处加连接<a href="load.asp?filename=ID"></a>

'以下代码保存为load.asp

<!--#include file="../CONN.asp"-->

<%Response.CodePage=936%>

<%Response.Charset="gb2312"%>

<%

Dim FileID

FileID = Request.QueryString("filename")

dim conn

makeconnect

sql="select id,shu,xzcs from dbo.表名 where ID="&FileID&""

set rs=conn.execute(sql)

Dim Stream

Dim FileName

Dim FilePath

Const adTypeBinary = 1

skid=rs(0)

FileName = rs(1)

xzcs= rs(2)

FilePath = "文件路径" '如../abc/

v1=Cstr(Request.ServerVariables("HTTP_REFERER"))

v2=Cstr(Request.ServerVariables("SERVER_NAME"))

v3=Request.ServerVariables("HTTP_USER_AGENT")

if mid(v1,8,len(v2))<>v2 or instr(v3,"Googlebot")>0 or instr(v3,"360Spider")>0 or instr(v3,"Baiduspider")>0 or instr(v3,"Baiduspider-render")>0 or instr(v3,"Sogou web spider")>0 or instr(v3,"YisouSpider")>0 or instr(v3,"Yahoo!")>0 or instr(v3,"bingbot")>0 or instr(v3,"Sosospider")>0 or instr(v3,"YodaoBot")>0 or instr(v3,"YoudaoBot")>0 or instr(v3,"msnbot-media")>0 or instr(v3,"ia_archiver")>0 or instr(v3,"EasouSpider")>0 or instr(v3,"JikeSpider")>0 or instr(v3,"EtaoSpider")>0 or request.cookies("xzcs"&FileID)="ok" then

else 

response.cookies("xzcs"&FileID) ="ok"

Response.Cookies("xzcs"&FileID).expires=date+1

conn.execute "update dbo.表名 set xzcs='"&xzcs+1&"' where id="&FileID

end if

Dim ContentType

Select Case lcase(Right(FileName, 4))

Case ".asf"

ContentType = "video/x-ms-asf"

Case ".avi"

ContentType = "video/avi"

Case ".doc"

ContentType = "application/msword"

Case ".zip"

ContentType = "application/zip"

Case ".xls"

ContentType = "application/vnd.ms-excel"

Case ".gif"

ContentType = "image/gif"

Case ".jpg", "jpeg"

ContentType = "image/jpeg"

Case ".wav"

ContentType = "audio/wav"

Case ".mp3"

ContentType = "audio/mpeg3"

Case ".mpg", "mpeg"

ContentType = "video/mpeg"

Case ".rtf"

ContentType = "application/rtf"

Case ".htm", "html"

ContentType = "text/html"

Case ".txt"

ContentType = "text/plain"

Case Else

ContentType = "application/octet-stream"

End Select

Set Stream = server.CreateObject("ADODB.Stream")

Stream.Mode = 3 '1 读,2 写,3 读写。

Stream.Type = adTypeBinary

Stream.Open

Stream.LoadFromFile Server.MapPath(FilePath&FileName&".txt")

Response.AddHeader "content-disposition", "attachment; filename="&FileName&".txt"

Response.AddHeader "Content-Length", Stream.size '通知浏览器接收的文件大小

Response.ContentType = ContentType

While Not Stream.EOS

Response.BinaryWrite Stream.Read(1024 * 64)

Response.Flush '立即发送(要求至少256字节),不加的话可能提示超过缓存区。

Wend

Stream.Close

Set Stream = Nothing

'Response.Flush

rs.close

set rs = nothing

conn.close

set conn = nothing

Response.End

%>


本文来自众享文库,转载请保留注明!

文库内容仅供参考,本站不保证其内容的有效性,如果您需解决具体问题(尤其法律、医学等领域)建议您详细咨询相关领域专业人士。
如果涉及不良内容、个人隐私、版权问题等,敬请举报投诉,本站将立即处理。

友情链接:手写查字典 小说下载查成语 经验文献
© 2017-2018 wenku.sharew.cn 桂ICP备13001205号-1 联系方式

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏