asp 如何弹出文件保存对话框??

astly2004 2006-01-23 04:50:55
asp 如何弹出文件保存对话框??

点击链接,弹出文件保存对话框,然后下载文件

不需要右键选择,而是点击直接弹出!!
...全文
286 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
astly2004 2006-01-23
  • 打赏
  • 举报
回复
wxf0104(西方失败007)

程序可以跑
能把 对话框默认的目录定死不??还有文件名,,就是只能下载,,目录和文件名都不可以改??
还有就是点击以后 出来 选择打开还是保存的对话框,,能不出来不??直接是保存的。。
帮忙看看
如果不行,我就结帖,给分了!!
wxf0104 2006-01-23
  • 打赏
  • 举报
回复
将下面的东西存成download.asp
然后你就可以用a herf="http://xxx.xxx.com/download.asp?n=file.doc">download!</a>
来下载了!
------------------------------------------------------------
<%
Response.Buffer = true
Response.Clear

dim url
Dim fso,fl,flsize
dim Dname
Dim objStream,ContentType,flName,isre,url1
'*********************************************调用时传入的下载文件名
Dname=trim(request("n"))
'******************************************************************
If Dname<>"" Then
'******************************下载文件存放的服务端目录
url=server.MapPath("/")&"\"&Dname
url=server.MapPath("./")&"\"&Dname '这边做了一下改动By Fanshui
'***************************************************
End If
'Response.write url
'response.end

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=" & flName
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

%>
astly2004 2006-01-23
  • 打赏
  • 举报
回复
谢谢,这种方式是可以
可是如何能控制对话框默认的目录呢?

能调用windows的那种保存文件框不??
meizz 2006-01-23
  • 打赏
  • 举报
回复
<input type=button value=保存 onclick="document.execCommand('SaveAs')">
<input type=button value=另存为 onclick="document.execCommand('Saveas',false,'c:\\test.htm')">

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧