一个关于下载的问题(100分)

nscoo 2005-06-21 10:15:01
条件
文件名存在数据库中,文件地址在e:\file\(服务器端),iis位置在c:\
我要怎么做这个程序才能下载到这个文件

比如
找到文件名为:abc.rar 位置是:e:\file\abc.rar (服务器端)
怎样通过点 abc.rar 下载到这个文件。
通过http:\\www.abc.com\down.asp?name=abc.rar下载到文件

还有
怎样做到下载任何文件。

之前
我做了一个,就是只能下载一个文件,而且不能用任何下载工具下载,只能用到windows的默认下载工具,用的是fso,怎样才能解决这个问题。

谢谢
...全文
154 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Karl_He 2005-06-22
  • 打赏
  • 举报
回复
IIS中把"e:\file\"另外设置为一个虚拟路径(file),如"http://(目标机或IP)/file/",
那么在下载页面就可以接受传入文件名前,
加上 "http://(目标机或IP)/file/" & request("abc.rar") 组成完整的下载字段,这里就能下载了
nscoo 2005-06-22
  • 打赏
  • 举报
回复
问题仍未解决
nscoo 2005-06-21
  • 打赏
  • 举报
回复
怎么没人顶啊
nscoo 2005-06-21
  • 打赏
  • 举报
回复
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--#include file="inc/conn.asp"-->'
<!--#include file="inc/add.asp"-->'判断文件夹地址文件
<%
orderid=request("orderid")
if orderid="" then
Response.write "<script language = 'javascript'>alert('数据库出错,请联系开发商');</script>"
Response.End
else
set Rs=Server.CreateObject("Adodb.Recordset")
Sql="Select * From orderinfo where orderid="&orderid
Rs.open Sql,conn,1,1
address=rs("file_outputfilename") '文件地址
SoftName=rs("file_outputfilename")

rs.close

fullfilename=orderfile& address'获取绝对路径
fullpath=orderfile'存放的物理路径

set obj_fso=server.createobject("scripting.filesystemobject")
if not obj_fso.fileexists(fullfilename) then '检测文件是否本服务器

Response.write "<script language = 'javascript'>alert('找不到该文件,或者该文件已经被删除!');location='admin_ordermanage.asp'</script>"
Response.End
else
FileExt = Mid(address, InStrRev(address, ".") + 1)
F_Ext=UCase(FileExt)
Select Case F_Ext
Case "ASP", "ASA", "ASPX", "ASAX", "MDB" '不允许下载的文件类型
response.write "<script language = 'javascript'>alert('该类型不允许下载,请联系管理员!');location='admin_ordermanage.asp'</script>"
Response.End
End Select
conn.execute("update orderinfo set file_down=true where orderid="&orderid)
call downloadFile(fullfilename,SoftName)
end if
end if


response.write """;" & VbCrLf
Response.write "</script>" & VbCrLf

Function downloadFile(strFile,FileName)
Dim s,fso,f,intFilelength,strFilename

strFilename = 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-Disposition", "attachment; filename=" & FileName '& "." & F_Ext'文件名加扩展名
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
Response.Write("<script>window.close();</script>")
Response.End()
End Function


' 判断数字是否整形,防止SQL注入
function isInteger(para)
on error resume next
dim str
dim l,i
if isNUll(para) then
isInteger=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isInteger=false
exit function
end if
l=len(str)

for i=1 to l
'判断字符的另一种方法
'dim element
' element=mid(str,i,1)
'REM asc 将字符转换成ASCII码,是否为0~9之间的数
' if (asc(element)<asc("0")) or (asc(element)>asc("9")) then
if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
isInteger=false
exit function
end if
next
isInteger=true
if err.number<>0 then err.clear
end function
%>
</body>

</html>

这是我的下载程序文件,就是可以下载,但是只能下载一个文件,而且不能想直接连接到文件那样调用flashget等下载工具,大文件速度就慢,我觉得指定虚拟目录这个方法是不好,如果文件夹多了,那就很麻烦了。
谁能帮我指出哪里不足啊
phyllis2001 2005-06-21
  • 打赏
  • 举报
回复
在iis中再建一个虚拟目录,指向e:\file,然后在下载的程序里判断就行了~~

28,405

社区成员

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

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