asp网站下载,asp文件下载

http://www.itjxue.com  2023-01-15 16:47  来源:未知  点击次数: 

ASP网站大文件下载的问题

%

host=Request.ServerVariables("HTTP_HOST")

fwym="http://" host Request.ServerVariables("SCRIPT_NAME")

wenjian=request("wenjian")

select case true

case right(lcase(wenjian),4)=".asp"

response.write "该类型文件不允许下载。"

response.end

case right(lcase(wenjian),4)=".php"

response.write "该类型文件不允许下载。"

response.end

case right(lcase(wenjian),5)=".aspx"

response.write "该类型文件不允许下载。"

response.end

end select

wenjian=replace(wenjian,"/","\")

a=split(wenjian,"\")

filename=a(ubound(a))

Set fso = CreateObject("Scripting.FileSystemObject")

fileurl=left(fwym,len(fwym)-8) wenjian

fileurl=replace(fileurl,"\","/")

if instr(1,wenjian,":")=0 then wenjian=server.mappath(wenjian)

'设置可下载文件大小上限

maxsize=50000000

'response.write wenjian

'response.end

set f1=fso.getfile(wenjian)

if f1.sizemaxsize then

response.write "文件太大了,不允许下载。" dxzh(f1.size) "只支持" dxzh(maxsize) "以内的文件下载"

response.end

end if

if instr(1,wenjian,":")=0 then

'response.write fileurl

response.redirect fileurl

response.end

end if

Response.ContentType = "application/octet-stream"

Response.AddHeader "content-disposition", "attachment; filename =" filename

set objstream = Server.CreateObject("adodb.stream")

objstream.Mode = 3

objstream.Type = 1

objstream.Open

objstream.LoadFromFile (wenjian)

BytesToBstr = objstream.Read

response.binarywrite BytesToBstr

function dxzh(dx)

zijieshu = dx "字节"

kbshu = FormatNumber(dx / 1024, "0.0") "KB"

mbshu = FormatNumber(dx / 1024 / 1024, 2) "MB"

fsize = dx

If fsize / 1024 1 Then dxzh = zijieshu

If fsize / 1024 = 1 And fsize / 1024 1024 Then dxzh = kbshu

If fsize / 1024 = 1024 Then dxzh = mbshu

end function

%

概述在ASP网站中文件下载功能如何实现?

文件下载只是个超链接,下载功能关键是和上传功能搭配使用,当上传完毕以后,程序自动将上传的文件所在位置链接保存到数据库,这样下载的时候直接读取打开链接即可下载!

ASP网站文件下载问题

浏览器可以直接显示的格式,就会直接打开。

如果一定要变成下载。可以用adodb.stream对象,以数据流的形式输出文件,并设置头部信息,使浏览器认为是供下载的数据流。

(责任编辑:IT教学网)

更多

推荐Freehand教程文章