我在做一个带有附件的发布系统。
附件文件保存到SQL中,表的“附件内容”字段类型为“IMAGE”。
在将“附件内容”读到页面a.asp中的时候,用了response.binaryWrite rs("附件内容")
在使用的时候,点击“附件1”这个超连接,就window.open "a.asp" 然后windows提示文件另存为“a.asp”,我将a.asp改名为b.exe(附件为b.exe文件),然后存到本地,能正确执行该操作。
现在我有个问题,就是能不能在点击“附件1”的时候,弹出的“文件另存为”的时候就自动将a.asp改为b.exe 而不必由用户自己修改为b.exe。我数据库有一个“附件文件名”字段,b.exe的文件名就保存在此字段。
请高手赐教,不胜感激!
document.execCommand(Saveas,false,c:\\b.exe)
在你的response.binaryWrite rs("附件内容")语句之前加上下面两句就行了。
Response.AddHeader "content-disposition", "attachment; filename=" & rs("附件文件名")
Response.ContentType = "Content-Type: application/octet-stream"
<%@ Language=VBScript %>
<%
filename=Request.QueryString("filename")
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
Const ForReading=1
Const TristateTrue=-1 Unicode
Const FILE_TRANSFER_SIZE=16384 16k
Use the following line for IIS4/PWS - this is the default for IIS5
Response.Buffer = True
Function TransferFile(path, mimeType, filename)
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
send=0
TransferFile = True
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(Path)
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)
Response.AddHeader "content-type", mimeType
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
Dim path, mimeType, sucess
Server.MapPath(path)
path = Server.MapPath(filename)
mimeType = "application/x-msdownload"
***********************************************
此处path为文件在服务器上路径,filename为想保存的name
success = TransferFile(path, mimeType,filename)
***********************************************
Response.End
%>
</BODY>
</HTML>