asp在IE瀏覽器中下載服務(wù)端上的各類文件的實現(xiàn)方法
更新時間: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ò)展名 站.長.站
' 通過文件擴(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ò)展名 站.長.站
' 通過文件擴(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)文章
ASP XMLDom在服務(wù)器端操作XML文件的主要方法和實現(xiàn)
我曾經(jīng)測試過不用數(shù)據(jù)庫,把網(wǎng)站的會員信息,商品數(shù)據(jù)信息,交易信息,網(wǎng)站定制信息全部存放在三個xml文件中,運(yùn)行結(jié)果十分正常,感覺上比數(shù)據(jù)庫快多了,不過沒有作測試,不能確定。2010-02-02asp中設(shè)置session過期時間方法總結(jié)
asp中默認(rèn)session過期時間為20分鐘,很多情況下不夠,今天有客戶要求很多就要重新登錄了,所以準(zhǔn)備了這篇文章,方便需要的朋友2012-09-09ASP讀取Request.QueryString編碼的函數(shù)代碼
ASP讀取Request.QueryString編碼的函數(shù)代碼,學(xué)習(xí)asp的朋友可以參考下。2011-09-09判斷dll文件是否已經(jīng)注冊的ASP函數(shù)代碼
有時候需要判斷服務(wù)器是否按照了dll文件,那么就可以參考下面的代碼進(jìn)行判斷。2011-09-09