นั่นคือมันแจ้งให้ผู้ใช้ดาวน์โหลดโดยตรงแทนที่จะเปิดไฟล์บางไฟล์โดยเบราว์เซอร์ โปรดทราบว่าหลังจากคัดลอกรหัสต่อไปนี้ไปยังไฟล์ ASP อย่าเพิ่มรหัสที่ไม่ใช่ ASP ลงในหน้า: เช่นรหัสไคลเอนต์ HTML และ JavaScript
การคัดลอกรหัสมีดังนี้:
-
-
response.buffer = true
dimstrfilepath, strfilesize, strfilename
ConstadTypeBinary = 1
strfilepath = "filepath"
strfilesize = ... ขนาดไฟล์เป็นทางเลือก
strfilename = "ชื่อไฟล์"
Response.Clear
'8 **********************************************
'ต้องการ MDAC2.6 หรือ MDAC2.7 ที่จะติดตั้งบนเซิร์ฟเวอร์ของคุณ
'8 **********************************************
setObjstream = server.createObject ("adodb.stream")
objstream.open
objstream.type = adtypebinary
objstream.loadFromFilestFilePath
strfileType = lcase (ขวา (strfilename, 4)) 'สถานีขยายไฟล์ยาว สถานี
'ตัดสินประเภทเนื้อหาโดยการขยายไฟล์
SelectCasEstRfileType
กรณี ".asf"
contentType = "video/x-ms-asf"
กรณี ".avi"
contentType = "วิดีโอ/avi"
กรณี ".doc"
ContentType = "Application/Msword"
กรณี ".zip"
contentType = "แอปพลิเคชัน/ซิป"
กรณี ".xls"
ContentType = "Application/vnd.ms-excel"
กรณี ".gif"
contentType = "image/gif"
กรณี ".jpg", "jpeg"
contentType = "image/jpeg"
กรณี ".wav"
ContentType = "Audio/Wav"
กรณี ".mp3"
ContentType = "Audio/MPEG3"
กรณี ".MPG", "MPEG"
contentType = "วิดีโอ/mpeg"
กรณี ".rtf"
ContentType = "Application/RTF"
กรณี ".htm", "html"
contentType = "ข้อความ/html"
กรณี ".asp"
contentType = "ข้อความ/asp"
caseelse
'handleallotherfiles
contentType = "แอปพลิเคชัน/อ็อกเท็ตสตรีม"
endelect
Response.addheader "เนื้อหา-การจัดสรร", "สิ่งที่แนบมา; ชื่อไฟล์ = strfilename
Response.addheader "ความยาวเนื้อหา", strfilesize
Response.charset = "UTF-8" 'ชุดอักขระของเบราว์เซอร์ลูกค้า UTF-8
Response.ContentType = ContentType
Response.binaryWriteobjstream.read
Response.flush
objstream.close
setObjstream = ไม่มีอะไร
-