<a>的关于文件下载的小问题谢谢
<a href= "www.baidu.com/1.doc " target= "_blank "> </a>
现在当点击这个连接的时候,1.doc文件在新的IE窗口中用WORD打开了文件。
我现在想做的是:点击这个链接,文件打开下载窗口,这样就可以把文件保存到本地。
请问这个问题该怎么解决?谢谢!
------解决方案-------------------- <a href= "DownFile.asp?NewsFile=www.baidu.com/1.doc " target= "_blank "> </a>
<!-------- DownFile.asp --------->
<%
dim NewsFile
NewsFile=request( "NewsFile ")
downLoadFile(NewsFile)
' ' '-----------------------------------文件下载---------------------------
Function downLoadFile(FileSpec)
on error resume next
Const ForReading=1
Const TristateTrue=-1
Const FILE_TRANSFER_SIZE=1024 '16384
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
Set objFileSystem = CreateObject( "Scripting.FileSystemObject ")
FileName = objFileSystem.GetFileName(FileSpec)
send=0
TransferFile = True
Set objFileSystem = Server.CreateObject( "Scripting.FileSystemObject ")
Set objFile = objFileSystem.GetFile(FileSpec)
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)
Response.AddHeader "content-type ", "application/octet-stream "
Response.AddHeader "Content-Disposition ", "attachment;filename= " & filename
Response.AddHeader "content-length ", objFile.Size
Do While Not objStream.AtEndOfStream
char = objStream.Read(1)
Response.BinaryWrite(char)
sent = sent + 1
If (sent MOD FILE_TRANSFER_SIZE) = 0 Then
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
Loop
Response.Flush
If Not Response.IsClientConnected Then TransferFile = False
objStream.Close
Set objStream = Nothing
Set objFileSystem = Nothing
End Function
%>