Ik ben bezig met het maken van een script waarmee bezoekers van ons intranet documenten e.d. automatisch kunnen downloaden. Het werkt prima wanneer het bijvoorbeeld een asp file is, echter wanneer het word of excell betreft wordt het betreffende bestand gewoon geopend in de browser. Wat zie ik over het hoofd? De search maakte me weinig wijzer...
filedownload.asp:
filedownload.asp:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
| <%
Response.Expires = 0
Dim objXMLHTTP
Dim objXml
Dim vFileName
Dim strFileReq
Dim strFileType
Dim strContentType
strFileReq = Request.QueryString("req")
If strFileReq = "" Then
%>
<html>
<head>
<title>Download a file</title>
</head>
<body>
<form method="get" action="<%= Request.ServerVariables("SCRIPT_NAME") %>">
<span style=" font-family:Verdana; font-size:12px;text-decoration:underline;">Enter the URL to the file you want download.</span><br/><br/>
<input type="text" size="30" name="req" value="" style="height:20px;border: black 1px solid; font-family: Verdana;">
<input type="submit" value="Retreive file" style="height:20px;font-family: Verdana; background-color: white; border: black 1px solid; font-weight:bold;">
</form>
</body>
</html>
<%
Else
On Error Resume Next
Set objXml = Server.CreateObject("Microsoft.XMLHTTP")
objXml.Open "GET", strFileReq, False
objXml.Send
If InStr(strFileReq,"/") <> 0 Then
vFileName = Split(strFileReq,"/")
strFileReq = Lcase(vFileName(UBound(vFileName)))
End If
Response.AddHeader "content-disposition","attachement;filename=" & strFileReq
If InStr(strFileReq,".") <> 0 Then
vFileName = Split(strFileReq,".")
strFileType = Lcase(vFileName(UBound(vFileName)))
End If
Select Case strFileType
Case "asf"
strContentType = "video/x-ms-asf"
Case "avi"
strContentType = "video/avi"
Case "doc"
strContentType = "application/vnd.ms-word"
Case "zip"
strContentType = "application/zip"
Case "xls"
strContentType = "application/vnd.ms-excel"
Case "gif"
strContentType = "image/gif"
Case "jpg", "jpeg"
strContentType = "image/jpeg"
Case "wav"
strContentType = "audio/wav"
Case "mp3"
strContentType = "audio/mpeg3"
Case "mpg", "mpeg"
strContentType = "video/mpeg"
Case "rtf"
strContentType = "application/rtf"
Case "htm", "html"
ContentType = "text/html"
Case "asp"
strContentType = "text/asp"
Case Else
strContentType = "application/octet-stream"
End Select
Response.Clear
Response.ContentType = strContentType
Response.BinaryWrite objXml.ResponseBody
Set objXml = Nothing
End If
%> |