图片下载

sunyz823 2012-08-24 03:31:45
怎么实现图片下载(代码)?急
...全文
68 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunyz823 2012-08-24
  • 打赏
  • 举报
回复
谢了。。。。。。。
sunyz823 2012-08-24
  • 打赏
  • 举报
回复
VB代码,asp.net简单点有吗?
ChinaXtHuLang 2012-08-24
  • 打赏
  • 举报
回复
另存为:Cls_DownFile.Asp
<%
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
%>


调用,另存为:down.asp
<!--#include file="Cls_DownFile.Asp" -->
<%
Dim CmsDownFile
Set CmsDownFile = New MainDownFile
CmsDownFile.SetSourceFilePath = "3.jpg"
CmsDownFile.SetNewFileName = "小军SB"
CmsDownFile.ShowDownFile()
%>


建立一个:index.asp
里面加上:<a href="down.asp">3.jpg</a>
这个:3.jpg你随便找个图片叫这个名字做测试。放到当前目录下。

别往了结贴

28,391

社区成员

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

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