asp在IE瀏覽器中下載服務(wù)端上的各類文件的實(shí)現(xiàn)方法
更新時(shí)間:2007年11月11日 21:51:53 作者:
即直接提示用戶下載而不是由瀏覽器打開某些文件。注意,下面的代碼拷貝到ASP文件中后,不要再添加一些非ASP代碼在頁面中:如HTML和javascript客戶端的代碼。
<%
'--------------------------------------------
Response.Buffer = True
Dim strFilePath, strFileSize, strFileName
Const adTypeBinary = 1
strFilePath = "文件路徑 "
strFileSize = ... 文件大小,可選
strFileName = "文件名"
Response.Clear
'8*******************************************8
' 需要在你的服務(wù)器上安裝 MDAC 2.6 或MDAC2.7
'8*******************************************8
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = lcase(Right(strFileName, 4)) '文件擴(kuò)展名 站.長(zhǎng).站
' 通過文件擴(kuò)展名判斷 Content-Types
Select Case strFileType
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 ".asp"
ContentType = "text/asp"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition", "attachment; filename= strFileName
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "UTF-8" ' 客戶端瀏覽器的字符集UTF-8
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
%>
復(fù)制代碼 代碼如下:
<%
'--------------------------------------------
Response.Buffer = True
Dim strFilePath, strFileSize, strFileName
Const adTypeBinary = 1
strFilePath = "文件路徑 "
strFileSize = ... 文件大小,可選
strFileName = "文件名"
Response.Clear
'8*******************************************8
' 需要在你的服務(wù)器上安裝 MDAC 2.6 或MDAC2.7
'8*******************************************8
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = lcase(Right(strFileName, 4)) '文件擴(kuò)展名 站.長(zhǎng).站
' 通過文件擴(kuò)展名判斷 Content-Types
Select Case strFileType
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 ".asp"
ContentType = "text/asp"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition", "attachment; filename= strFileName
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "UTF-8" ' 客戶端瀏覽器的字符集UTF-8
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
%>
相關(guān)文章
做文章系統(tǒng)時(shí), 如何讓長(zhǎng)篇的文章自動(dòng)換行
做文章系統(tǒng)時(shí), 如何讓長(zhǎng)篇的文章自動(dòng)換行...2006-09-09
asp使用Weekday函數(shù)計(jì)算項(xiàng)目的結(jié)束時(shí)間
在asp編程開發(fā)中,計(jì)算時(shí)間很容易,直接用項(xiàng)目開始時(shí)間+天數(shù),即可得到項(xiàng)目結(jié)束時(shí)間,但這里麻煩就在要排除周六和周日這兩個(gè)休息時(shí)間2017-04-04
ASP 代碼出現(xiàn)80040e14錯(cuò)誤的解決方法
本文減淡概述了解決80040e14錯(cuò)誤的兩種方法。2009-04-04
循環(huán)取值Request.QueryString的用法
2008-01-01
asp 讀取通過表單發(fā)送的post數(shù)據(jù)
學(xué)習(xí)ASP,最重要的就是要掌握ASP內(nèi)置的六大對(duì)象,如果以前沒接觸過,聰明的您就不要管這些概念了,知道怎么用就行了,我的觀點(diǎn)是剛開始關(guān)鍵在于臨摹2012-12-12

