急在线等一个简单的问题?

jiazhuo 2003-09-14 12:44:09
我刚学ASP的请问怎么做一个下载的程序?比如说我要做一个软件下载的的页面请问代码怎么写?
...全文
35 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lions911 2003-09-14
  • 打赏
  • 举报
回复
<a href="a.doc">a.doc</a>
xiaoxingchi 2003-09-14
  • 打赏
  • 举报
回复
www.asp300.com
这里面有的是代码,下一个下来慢慢看·不懂的再来问!
zxll5523613 2003-09-14
  • 打赏
  • 举报
回复
同上
匿名用户8823 2003-09-14
  • 打赏
  • 举报
回复
解决这个问题有以下三种方法:

1、把a.doc文件打包成a.rar或者a.zip。别人打开ie自动下载

2、在web服务器的配置文件中加入.doc文件类型

3、编程实现,具体程序如下:(我一直收藏着的,你直接复制粘贴下来,存成.asp文件就行了!!)

<%
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
'***************************************************
End If

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

%>
ljupin 2003-09-14
  • 打赏
  • 举报
回复
soft.asp

<a href="download.asp?id=1">下载该软件</a>

download.asp

<%
<!--#include file="conn.asp" -->
set rs=server.createobject("adodb.recordset")
rs.open" Select url From table where id="&Request.QueryString("id")&" ',conn,1,3

if rs.bof then
Response.Write("没有该软件")
Response.End
end if
rs("hit")= rs("hit") + 1 '更新下载次数
rs.update

dim url
url = rs("url")
set rs=nothing

Response.Redirect(url)
%>

28,391

社区成员

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

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