引用:填充Response

类别:Asp 点击:0 评论:0 推荐:

回复人: appleboyallen(揪揪) ( ) 信誉:100  2002-06-28 20:50:25Z  得分:50
 
 
 
可以把文件放到用户不能到达的地方,然后在asp文件中用binaryread,的方法发给用户,这里有一个函数,
Const ForReading=1
Const TristateTrue=-1
Const FILE_TRANSFER_SIZE=16384
Function TransferFile(path, mimeType)
    Dim objFileSystem, objFile, objStream
    Dim char
    Dim sent
    send=0
    TransferFile = True
    set objFileSystem=server.CreateObject("scripting.filesystemobject")
    Set objFile = objFileSystem.GetFile(path)
    Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)
    Response.AddHeader "content-type", mimeType
    Response.AddHeader "Content-Disposition","attachment;filename="&file_name
    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  mimeType, sucess
mimeType = "application/x-msdownload"
file_path=server.MapPath("software/" & file_name )
success = TransferFile(file_path, mimeType)
%>
 

本文地址:http://com.8s8s.com/it/it8074.htm