我用了下面的代码:
<%
call downloadFile(Request("path"))
function downloadFile(strFile)
strFilename = server.MapPath(strFile)
Response.Buffer = True
Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
on error resume next
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
Response.End
end if
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
Response.End
end if
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite s.Read
Response.Flush
s.Close
Set s = Nothing
End Function
%>
将上面的代码另存为down.asp放在要附件的目录下面(比如UpLoadFile/),然后引用:
<a href="UpLoadFile/down.asp?path=<%=rs("path")%>">点击下载</a>
UPDATE @ 2007.03.29:先道歉,上面的代码有一些问题,别人可以下载你的任何文件!fisker给出的补丁是在
function downloadFile(strFile)
后面加上
if left(strFile,1)="/" or
left(strFile,1)="\" or
left(strFile,2)=".." then response.end
if left(path,1)="/" or left(path,3)="../" then response.end
回覆刪除非常想请教您一个问题,您是怎么实现wordpress的静态化的?用某个插件还是?
回覆刪除请问您的wordpress是如何实现静态化的?我尝试了很多办法都没有奏效,还请指教~~
回覆刪除WP自带的“设置”--》“永久链接”
回覆刪除[...] 不过,看到了另外一个报道,明白上次我写的不直接打开而是另存为的作用了吧,就是《钢铁之花》的pdf另存为啦。 [...]
回覆刪除