zoukankan      html  css  js  c++  java
  • 用ASP实现文件下载

    <% 
    '**************************************************************
    '**使用方法:                                                **
    '**在点击下载处加连接<a href="load.asp?filename=文件名"></a> **
    '**阳光白雪——2005年11月21日                                **
    '**E-mail:chenmanyi0818@126.com                              **
    '**HomePage:http://www.toumh.com ;                          **
    '**************************************************************
    '**************************************************
    '**              实现文件下载函数                **
    '**************************************************
    Function Filedownload(filename) 
      Dim strchar,fliesend,objectFile,objfile,objStream,path,pathtype
      pathtype = "application/x-msdownload" 
      path = server.MapPath(filename)
      Const loadfilesize=32768 '32KB,也可取其它值,单位:字节
      '在给path赋值后,其最终值必定是该图片在服务器端存储器上的绝对路径,如 C:Inetpubwwwrootpichelp.gif
      '因为 server.MapPath 取得的只是站点根目录的路径,所以在后面还应加上文件所在的文件夹再加文件名
      '例如:要下载的文件 setup.exe 在根目录的 download 文件夹下,则 path = server.MapPath("download/"&filename)
      '***********************************
      '测试用
      'response.Write(path)
      'response.Write(filename)
      'response.End()
      '***********************************
      fliesend=0 
      TransferFile = True 
      Set objectFile = Server.CreateObject("Scripting.FileSystemObject") 
      Set objfile = objectFile.GetFile(Path) 
      Set objStream = objfile.OpenAsTextStream(1,-1) 
      Response.AddHeader "content-type", pathtype 
      response.AddHeader "Content-Disposition","attachment;filename="&filename 
      Response.AddHeader "content-length", objfile.Size 
       Do While Not objStream.AtEndOfStream 
         strchar = objStream.Read(1) 
         Response.BinaryWrite(strchar) 
         fliesend = fliesend + 1 
         If (fliesend MOD loadfilesize) = 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
      end if
      objStream.Close 
      Set objStream = Nothing 
      Set objectFile = Nothing 
    End Function 
    '****************************************************
    '**               文件下载函数结束                 **
    '****************************************************
    Dim fileneme,downloadfile 
    filename = request("filename")  '此处的 filename 仅为下载文件的名称(包括扩展名)
    downloadfile = Filedownload(filename) '调用文件下载函数
    Response.End
    %>

  • 相关阅读:
    flutter PageView实现左右滑动切换视图
    Flutter进阶:在应用中实现 Hero(飞行) 动画
    阿里云申请免费SSL证书,并配置到Tomcat,实现https访问
    Tomcat 部署项目的三种方法
    idea jsp文件中body标签内引入编辑器后提示statement expected
    UEditor设置内容setContent()失效的解决方法
    UEditor API
    easyui-dialog打开之后append("标签")标签存在但是显示不出来
    combogrid下拉方法封装
    java中try 与catch的使用
  • 原文地址:https://www.cnblogs.com/bit5566/p/5671554.html
Copyright © 2011-2022 走看看