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

首頁 > 編程 > ASP > 正文

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

2024-05-04 10:57:43
字體:
來源:轉載
供稿:網友
即直接提示用戶下載而不是由瀏覽器打開某些文件。注意,下面的代碼拷貝到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
%> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 怀仁县| 汝阳县| 阿拉善盟| 钦州市| 正安县| 桃源县| 丹寨县| 泰来县| 那曲县| 洞口县| 七台河市| 宜都市| 贵港市| 揭东县| 论坛| 杂多县| 禄劝| 宁强县| 资源县| 象州县| 忻城县| 涞源县| 西和县| 加查县| 瑞丽市| 凭祥市| 富平县| 临沂市| 望城县| 囊谦县| 新龙县| 榕江县| 潍坊市| 焦作市| 九龙县| 苏尼特左旗| 广汉市| 土默特左旗| 涞源县| 乐昌市| 罗江县|