国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

asp在IE瀏覽器中下載服務端上的各類文件的實現方法

2024-05-04 11:01:04
字體:
來源:轉載
供稿:網友
即直接提示用戶下載而不是由瀏覽器打開某些文件。注意,下面的代碼拷貝到ASP文件中后,不要再添加一些非ASP代碼在頁面中:如HTML和javascript客戶端的代碼。 
復制代碼 代碼如下:
<%
'--------------------------------------------
Response.Buffer = True
Dim strFilePath, strFileSize, strFileName
Const adTypeBinary = 1
strFilePath = "文件路徑 "
strFileSize = ... 文件大小,可選
strFileName = "文件名"
Response.Clear
'8*******************************************8
' 需要在你的服務器上安裝 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)) '文件擴展名 站.長.站 
' 通過文件擴展名判斷 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
%> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金阳县| 天等县| 从江县| 通山县| 五峰| 明星| 竹北市| 陇川县| 启东市| 盖州市| 西乌珠穆沁旗| 东阳市| 安阳市| 连江县| 房山区| 新巴尔虎左旗| 安图县| 搜索| 乐山市| 禹州市| 扎鲁特旗| 家居| 奈曼旗| 东乌珠穆沁旗| 大关县| 历史| 香港 | 崇礼县| 全椒县| 息烽县| 嘉鱼县| 东源县| 天全县| 义马市| 敦化市| 北京市| 黑山县| 枣强县| 岱山县| 抚顺市| 靖江市|