为什么不能下载

yinjor 2008-11-23 10:20:50


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../ado/adoconn.asp"-->
<%
Public Function dl(f,n)
on error resume next
set s=CreateObject("Adodb.Stream")
S.Mode=3
S.Type=1
S.Open
s.LoadFromFile(f)
if err.number>0 then
response.write err.number & ":" & err.description
else
response.contentType="application/x-gzip"
response.addheader "Content-Disposition:","attachment; filename=" & n
response.binarywrite(s.Read(s.size))
end if
end Function


Public Function FILES_Sel(argLongFILEID)
Dim strSql,cmd
Dim paraArray(1)
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = Conn
cmd.CommandType = adCmdText
strSql = "select [FILENAME] ,[FILEPATH], [FILEEXT] from [FILES] where [FILEID]=?"
cmd.CommandText = strSql
cmd.Prepared = True
Set paraArray(0) = cmd.CreateParameter ("FILEID",adInteger, adParamInput, 4, argLongFILEID)
cmd.Parameters.Append(paraArray(0))
set FILES_Sel = cmd.Execute()
End Function

Dim LongFILEID,rs,strFileName,strDFileName,strFileExt
'---- 文件上传的路径
dim outFileFolder '文件夹路径
dim StrConFolder '文件夹对虚拟目录上级目录的后面部分地址
outFileFolder = server.MapPath(".")
StrConFolder = "others\"
outFileFolder = Left(outFileFolder,InStrRev(outFileFolder, "\wwwroot")) '\himygod为所在虚拟目录的主路径,outFileFolder此时的址此是其上级目的路径\
outFileFolder = outFileFolder & StrConFolder

if Request.QueryString("fileid")<>"" then
LongFILEID = Request.QueryString("fileid")
set rs=FILES_Sel(LongFILEID)
strDFileName = Trim(rs(0))
strFileName = Trim(rs(1))
strFileExt = Trim(rs(2))
rs.Close
Conn.Close
set Conn = nothing
strFileName = outFileFolder & strFileName
strDFileName = strDFileName & "." & strFileExt
dl strFileName,strDFileName
end if
%>

我想用这个页面来下载站外的文件,本机上没有问题,但一传到空间上就下载不了
其中上传,删除都没有问题,高手指点一下啊
...全文
86 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
virgo2008 2008-11-23

<style>
body{font-size:9pt;
color:red;
}
td{font-size:9pt;
}
</style>
<%
Const ForReading=1
Const TristateTrue=-1 'Unicode
Const FILE_TRANSFER_SIZE=16384 '16k

'Use the following line for IIS4/PWS - this is the default for IIS5
Response.Buffer = True

Function TransferFile(path, mimeType, filename)
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
send=0
TransferFile = True

Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")

If objFileSystem.FileExists(Server.MapPath(Path)) Then
Set objFile = objFileSystem.GetFile(Server.MapPath(Path))
Else
Response.Write "<table width='25%' border='0' align='center' cellpadding='5' cellspacing='0'>"
Response.Write " <tr>"
Response.Write " <td><img src='Images/Error/01.jpg' width='447' height='183' /></td>"
Response.Write " </tr>"
Response.Write " <tr>"
Response.Write " <td align='center' valign='middle'>文件"&" "&Ucase(OldFileName)&" "&"不存在</td>"
Response.Write " </tr>"
Response.Write "</table>"
Response.End
end if
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)

Response.AddHeader "content-type", mimeType
response.AddHeader "Content-Disposition","attachment;filename="&filename
Response.AddHeader "content-length",objFile.Size

Do While Not objStream.AtEndOfStream
char = objStream.Read(1)
Response.BinaryWrite(char)
sent = sent + 1
If (sent MOD FILE_TRANSFER_SIZE) = 0 Then
Response.Flush
If Not Response.IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
Loop

Response.Flush
If Not Response.IsClientConnected Then TransferFile = False

objStream.Close
Set objStream = Nothing
Set objFileSystem = Nothing
End Function

Dim path, mimeType, sucess

FileName = Request.QueryString("FileName")
mimeType = "application/x-msdownload"
OldFileName = mid(FileName,instrrev(FileName,"/")+1)

if FileName = "" Then
Response.Write "无效文件名!"
Response.End
End if
FileExt = Mid(FileName, InStrRev(FileName,".") + 1) '取下载文件的后缀名
Select Case UCase(FileExt)
Case "ASP", "ASA", "ASPX", "ASAX", "MDB" ,"Jsp" ," Php"
Response.Write "<table width='25%' border='0' align='center' cellpadding='5' cellspacing='0'>"
Response.Write " <tr>"
Response.Write " <td><img src='Images/Error/01.jpg' width='447' height='183' /></td>"
Response.Write " </tr>"
Response.Write " <tr>"
Response.Write " <td align='center' valign='middle'>非法操作!禁止下载"&" "&Ucase(FileExt)&" "&"文件</td>"
Response.Write " </tr>"
Response.Write "</table>"
Response.End
End Select

sucess = TransferFile(FileName,mimeType,OldFileName)

%>
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-11-23 10:20
社区公告
暂无公告