ASP程序中,有一些附件并不希望用已知程序直接打开,而是想点击时弹出下载提示。
我用了下面的代码:
<%
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
> yskin Says:
Warning: Undefined variable $comment in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 29
Warning: Attempt to read property "comment_approved" on null in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 29
21 3 月, 2007 at 下午12:40
我用的
Header add Content-Disposition "Attachment"
,在.htaccess文件里。呃,如果是单独的文件,比如txt文件,可以用Header命令,如果是asp等程序处理,还是Content-Disposition比较好吧,可以指定保存成的文件的文件名。http://wordpress.org/latest.zip就是这样的吧。
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 252
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 253
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 252
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 253
> fisker Says:
Warning: Undefined variable $comment in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 29
Warning: Attempt to read property "comment_approved" on null in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 29
21 3 月, 2007 at 下午5:37
if left(path,1)=”/” or left(path,3)=”../” then response.end
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 252
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 253
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 252
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 253
> Angelived Says:
Warning: Undefined variable $comment in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 29
Warning: Attempt to read property "comment_approved" on null in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 29
24 3 月, 2007 at 上午3:06
非常想请教您一个问题,您是怎么实现wordpress的静态化的?用某个插件还是?
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 252
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 253
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 252
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 253
> Angelived Says:
Warning: Undefined variable $comment in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 29
Warning: Attempt to read property "comment_approved" on null in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 29
24 3 月, 2007 at 上午3:07
请问您的wordpress是如何实现静态化的?我尝试了很多办法都没有奏效,还请指教~~
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 252
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 253
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 252
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 253
> OtherSide » pdf另存为的作用 Says:
Warning: Undefined variable $comment in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 29
Warning: Attempt to read property "comment_approved" on null in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 29
3 4 月, 2007 at 上午10:07
[…] 不过,看到了另外一个报道,明白上次我写的不直接打开而是另存为的作用了吧,就是《钢铁之花》的pdf另存为啦。 […]
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 252
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 253
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 252
Warning: Attempt to read property "user_level" on bool in /www/wwwroot/wordpress/wp-includes/deprecated.php on line 253
Warning: Undefined variable $oddcomment in /www/wwwroot/wordpress/wp-content/themes/OtherSide/comments.php on line 86