如何实现word文挡下载?在线等待?????
我现在想在网页上实现让客户端可以直接下载我的word文挡,可是如果客户端安装了office的话,它自动就会打开这个word文挡,如果把这个word文挡做成.rar文件就可以下载了,请各位高手指教,能在客户端直接下载.doc的word文挡???? 问题点数:0、回复次数:6Top
1 楼scoutlin(挖摸追挖摸追挖摸追..)回复于 2005-03-03 19:34:47 得分 0
Function DownFile2(strFile)
strFilename = server.MapPath(strFile)
fname=instrrev(replace(strFile,"\","/"),"/")
if fname>0 then
fname=right(strFile,len(strFile)-fname)
else
fname=strFile
end if
Response.ContentType = "application/x-download"
Response.AddHeader "content-disposition", "attachment; filename=" &fname
set Stream=CreateObject("Adodb.Stream")
Stream.Type = 1
Stream.Open
Stream.LoadFromFile strFilename
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
End FunctionTop
2 楼bluemoon0001(小天--追梦浪子)回复于 2005-03-03 22:26:33 得分 0
<a href='downattach.asp?n=123456.doc&upname=下载保存时默认的文件名.doc'>说明文字</a>
downattach.asp:
<%
Response.Buffer = true
Response.Clear
dim url
Dim fso,fl,flsize
dim Dname
Dim objStream,ContentType,flName,isre,url1
'*********************************************调用时传入的下载文件名
Dname=trim(request("n"))
upname=trim(request("upname"))
'******************************************************************
If Dname<>"" Then
'******************************下载文件存放的服务端目录
url=server.MapPath("Download/")&"\"&Dname
'***************************************************
End If
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set fl=fso.getfile(url)
flsize=fl.size
flName=fl.name
Set fl=Nothing
Set fso=Nothing
%>
<%
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile url
Select Case lcase(Right(flName, 4))
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 ".txt"
ContentType = "text/plain"
Case Else
ContentType = "application/octet-stream"
End Select
Response.AddHeader "Content-Disposition", "attachment; filename=" & upname
Response.AddHeader "Content-Length", flsize
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
response.Clear()
objStream.Close
Set objStream = Nothing
%>
Top
3 楼kkwu(转圈)回复于 2005-03-07 18:35:55 得分 0
该程序不能下超过5M的文件呀,怎么办?Top
4 楼xhlin(HeaD)回复于 2005-03-07 19:54:07 得分 0
看着都晕,超过5M就让他去fttp下载去Top
5 楼hhjjhjhj(大头)(http://office.9zp.com)回复于 2005-03-07 19:58:41 得分 0
IIS中设置一下就可以了。
IIS中找到xxxx.doc,右击--属性--HTTP头---MIME---新建
doc
application/octet-stream
这样:<a href="xxxx.doc">doc</a> 就会下载(不会在IE打开)
也可对文件夹,网站设置MIME。Top
6 楼fangsky(成雨)回复于 2005-03-17 09:40:13 得分 0
to:bluemoon0001(小天--追梦浪子)
我使用你的代码,下载下来的word文件,内容变成了乱码
Top




