在线客服,智能在线客服,在线客服系统,客服机器人,智能客服,智能机器人客服,电商客服系统,智慧客服,免费电话,微信在线客服,网站在线客服软件,网络营销电话,手机在线客服,微客服,快商通

咨询热线:400-027-0592 

asp下载文件代码总结

分类:快商学院 时间:2012-10-13 作者:


QQ空间 新浪微博 腾讯微博 更多

 

挺好用的,整理收藏起来.

<[email protected]="VBSCRIPT" CODEPAGE="65001"%>
<%
Response.codepage="65001"
Response.Charset="utf-8"
%>
<!--#include file="easp/easp.asp"-->
<%
Response.Buffer=true

dim url,trueurl

   url=Easp.Ext("myfunc").objdetailinfo("download","id",Easp.Get("id")).item("downfile")
  sz=instrrev(PATH,"\")+1
  fname=mid(path,sz)
   call DownloadFile(url,fname)
'call downfile(server.MapPath(url))
sub downfile(path)
 response.CLeaR
 Set osm = server.createobject("adodb.stream")
 osm.open
 osm.TypE = 1
 osm.loadfromfile path

 sz=instrrev(PATH,"\")+1
  select case lcase(right(sz,4))
      case ".asf"
      response.ContentType="video/x-ms-asf"
      case ".avi"
      response.ContentType="video/avi"
      case ".doc"
      response.ContentType="application/msword"
      case ".zip"
      response.ContentType="application/zip"
      case ".xls"
      response.ContentType="application/vnd.ms-excel"
      case ".gif"
      response.ContentType="image/gif"
      case ".jpg","jpeg"
      response.ContentType="image/jpeg"
      case ".wav"
      response.ContentType="audio/wav"
      case ".mp3"
      response.ContentType="audio/mpeg3"
      case ".mpg", "mpeg"
      response.ContentType="video/mpeg"
      case ".rtf"
     response.ContentType="application/rtf"
      case ".htm","html"
      response.ContentType="text/html"
      case ".txt"
      response.ContentType="text/plain"
  Case ".ASP", ".ASA", "ASPX", "ASAX", ".MDB"
        Response.Write "受保护文件,不能下载."
        Response.End
      case else
      response.ContentType="appliation/octet-stream"
   end select
 response.addheader "Content-Disposition", "attachment; filename=" & mid(path,sz)
 response.addheader "Content-Length", osm.size
 response.charset = "UTF-8"
 'response.contenttype = "application/octet-stream"
 response.binarywrite osm.read
 response.flush
 osm.close
 set osm = nothing
end sub

Function getFileInfo(FileName)
    Dim FSO, File, FileInfo(10)
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    If FSO.FileExists(Server.MapPath(FileName)) Then
        Set File = FSO.GetFile(Server.MapPath(FileName))
        FileInfo(0)=File.Size
        If FileInfo(0)>1024 Then
          FileInfo(0)=Round(FileInfo(0) / 1024,2)
        If FileInfo(0) > 1024 Then
          FileInfo(0)=Round(FileInfo(0) / 1024,2)
          FileInfo(0)= FileInfo(0) & " MB"
        Else
         FileInfo(0)= FileInfo(0) & " KB"
        End If
        Else
          FileInfo(0)= FileInfo(0) & " Byte"
        End If
        FileInfo(1) = LCase(Right(FileName, 4))
        FileInfo(2) = File.DateCreated
        FileInfo(3) = File.Type
        FileInfo(4) = File.DateLastModified
        FileInfo(5) = File.Path
        FileInfo(6) = "" 'File.ShortPath 部分服务器不支持
        FileInfo(7) = File.Name
        FileInfo(8) = "" 'File.ShortName 部分服务器不支持
        FileInfo(9) = FSO.getExtensionName(Server.MapPath(FileName))
        FileInfo(10) = File.DateLastModified
    End If
    getFileInfo = FileInfo
    Set FSO = Nothing
End Function

Function DownloadFile(strFile,filename)
'Program:54powerman
'email:[email protected]
'HomePage: http://blog.sina.com.cn/u/1055000490
'Writen:2003-4
'确保系统安装了最新版的MDAC
' -------------------------------------------------------------
strFilename = server.MapPath(strFile)
'清空Buffer
Response.Buffer = True
Response.Clear
'创建Stream对象
Set s = Server.CreateObject("ADODB.Stream")
s.Open
'设置流对象为二进制类型
s.Type = 1
on error resume next
'检测文件是否存在
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(strFilename) Then
downloadFile="NoFile"
Exit Function
End If
'计算文件长度
Set f = fso.GetFile(strFilename)
intFilelength = f.size
If filename="" Then
filename=f.name
End If
s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
Response.End
end if
'向用户浏览器发送Header
Response.AddHeader "Content-Disposition", "attachment; filename=" & filename
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
'输出文件
'对于小于4096KB的文件可以用语句
'Response.BinaryWrite s.Read
'Response.Flush
'完成,但对于大于4096KB的文件要分段输出,如下循环操作。
Do While Not s.EOS
 Contents = s.Read (4096) '每次读取4096KB
 Response.BinaryWrite Contents
 Response.Flush
Loop

'清理
s.Close
Set s = Nothing
End Function

%>
返回列表>>

上一篇:RDBMS 数据库设计——产品-属性表

下一篇:ECShop仿淘宝商品详细页 实现尺码颜色


相关新闻

短信最新公告

快商通与中国电信再度升级合作

马年佳音频传,喜讯振奋人心

快商通2014新年祝福暨春节放假通知

快商软件喜获“全国中小企业生产经营运行监测厦门样本企业”称号

客服一对一服务
30万成功案例
CCTV央视特别报道
国家高新技术企业
全国统一咨询热线:400-027-0592