直接下栽WORD文件

我在网页上有一个连接。连接的内容是*.doc ,我想实现的是在用鼠标(左击)点击时出现另存窗口,而不是直接打开该文件
---------------------------------------------------------------

你写一个DL.asp文件,这个文件源码如下:


dl.asp


 1   
 2Response.Buffer = true   
 3Response.Clear   
 4  
 5'获取要下载的文件在服务器上的绝对位置   
 6dlfile=trim(request("dlfile"))   
 7If dlfile<>"" Then   
 8fileurl=server.MapPath(dlfile)   
 9Else   
10Response.end   
11End If   
12  
13'创建Myfso,使用FSO组件   
14Set Myfso=Server.CreateObject("Scripting.FileSystemObject")   
15Set f=Myfso.getfile(fileurl) '定义FSO对象f   
16fsize=f.size '文件大小   
17fName=f.name '文件名字   
18Set f=Nothing '释放f   
19Set Myfso=Nothing '释放MyFso   
20  
21'使用Adodb.Stream组件   
22Set MyStream = Server.CreateObject("ADODB.Stream")   
23MyStream.Open   
24MyStream.Type = 1   
25MyStream.LoadFromFile fileurl   
26  
27'读取文件类型,让系统识别,以存为不同类型的文件。   
28Select Case lcase(Right(fName, 4))   
29Case ".asf"   
30ContentType = "video/x-ms-asf"   
31Case ".avi"   
32ContentType = "video/avi"   
33Case ".doc"   
34ContentType = "application/msword"   
35Case ".zip"   
36ContentType = "application/zip"   
37Case ".xls"   
38ContentType = "application/vnd.ms-excel"   
39Case ".gif"   
40ContentType = "image/gif"   
41Case ".jpg", "jpeg"   
42ContentType = "image/jpeg"   
43Case ".wav"   
44ContentType = "audio/wav"   
45Case ".mp3"   
46ContentType = "audio/mpeg3"   
47Case ".mpg", "mpeg"   
48ContentType = "video/mpeg"   
49Case ".rtf"   
50ContentType = "application/rtf"   
51Case ".htm", "html"   
52ContentType = "text/html"   
53Case ".asp"   
54ContentType = "text/html"   
55Case ".txt"   
56ContentType = "text/plain"   
57Case Else   
58ContentType = "application/octet-stream"   
59End Select   
60  
61'下载   
62Response.AddHeader "Content-Disposition", "attachment; filename=" & fName   
63Response.AddHeader "Content-Length", fsize   
64Response.Charset = "UTF-8"   
65Response.ContentType = ContentType   
66Response.BinaryWrite MyStream.Read   
67Response.Flush   
68  
69'释放MyStream   
70MyStream.Close   
71Set MyStream = Nothing   

然后你在要实现的页面中这样调用:


1<a href="dl.asp?dlfile=dl.doc">dl.doc</a>

Published At
Categories with Web编程
comments powered by Disqus