Das heißt, es fordert den Benutzer direkt auf, bestimmte Dateien vom Browser herunterzuladen, anstatt sie zu öffnen. Beachten Sie, dass nach dem Kopieren des folgenden Codes in die ASP-Datei keinen Nicht-Asp-Code zur Seite hinzufügen: wie HTML- und JavaScript-Client-Code.
Die Codekopie lautet wie folgt:
<%
'----------------------------------------
Response.buffer = true
DimstrFilepath, Strfilesize, Strafilename
Constadypebinary = 1
strFilepath = "filepath"
strFileSize = ... Dateigröße, optional
strFileName = "Dateiname"
Antwort.Clear
'8************************************************8
'Erfordert MDAC2.6 oder MDAC2.7, auf Ihrem Server installiert zu werden
'8************************************************8
SetObjstream = server.createObject ("adodb.stream")
objstream.open
objstream.type = adypebinary
Objstream.loadfromFilestripilePath
strFiletype = lase (rechts (strFileName, 4)) 'Dateierweiterungsstation.long. Station
'Inhaltstypen nach Dateierweiterung beurteilen
SelectCassterFileType
Fall ".asf"
ContentType = "Video/X-MS-Asf"
Fall ".AVI"
ContentType = "Video/avi"
Fall ".doc"
ContentType = "application/msword"
Fall ".zip"
ContentType = "Anwendung/ZIP"
Fall ".xls"
ContentType = "application/vnd.ms-excel"
Fall ".gif"
ContentType = "Image/GIF"
Case ".jpg", "jpeg"
ContentType = "Image/JPEG"
Fall ".wav"
ContentType = "audio/wav"
Fall ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "Video/mpeg"
Fall ".Rtf"
ContentType = "application/rtf"
Fall ".htm", "html"
ContentType = "text/html"
Fall ".asp"
ContentType = "Text/ASP"
Fallelse
'Handleallotherfiles
ContentType = "Anwendung/Oktettstream"
Endauswahl
Response.addHeader "Inhaltsdisposition", "Anhang; Dateiname = strFileName
Response.addHeader "Content-Length", strFileSize
Response.charset = "utf-8" 'Customer Browsers Charakter Set UTF-8
Antwort.ContentType = contentType
Response.binarywriteObjstream.read
Antwort.Flush
objstream.close
SetObjstream = nichts
%>