日期:2014-05-17  浏览次数:20961 次

图片下载
怎么实现图片下载(代码)?急

------解决方案--------------------
另存为:Cls_DownFile.Asp
VB code
<%
Class MainDownFile
    Private mSourceFilePath
    Private mNewFileName

    '=====================================================
    ' 设置源文件路径
    '=====================================================

    Public Property Let SetSourceFilePath(ByVal NewVal)
        mSourceFilePath = Server.MapPath(NewVal)
    End Property

    '=====================================================
    ' 设置新文件名
    '=====================================================

    Public Property Let SetNewFileName(ByVal NewVal)
        mNewFileName = NewVal
    End Property

    Private Sub Class_Initialize()

    End Sub

    Public Sub ShowDownFile()
        Dim AdoStr
        Set AdoStr = CreateObject("Adodb.Stream")
        AdoStr.Mode = 3
        AdoStr.Type = 1
        AdoStr.Open
        AdoStr.LoadFromFile(mSourceFilePath)
        If Err.Number > 0 Then
            Response.Status = "404"
        Else
            Response.ContentType = "application/octet-stream"
            Response.AddHeader "Content-Disposition:", "attachment; filename=" & RemoteNewFile()
            Range = Mid(Request.ServerVariables("http_range"), 7)
            If Range = "" Then
                Response.BinaryWrite(AdoStr.Read)
            Else
                AdoStr.position = CLng(Split(Range, "-")(0))
                Response.BinaryWrite(AdoStr.Read)
            End If
        End If
        Set AdoStr = Nothing
    End Sub

    '========================================================
    '函数名:GetExt
    '作  用:获取文件后缀
    '参  数:FileName为文件名
    '返回值:文件后缀,不包含点,如:index.html = html
    '========================================================

    Private Function GetExt(FileName)
        GetExt = Mid(FileName, InstrRev(FileName, ".") + 1)
    End Function

    Private Function RemoteNewFile()
        Dim mNewFile
        mNewFile = GetExt(mSourceFilePath)
        RemoteNewFile = mNewFileName & "." & mNewFile
    End Function

End Class
%>