文章分类 Classification
FSO生成目录树并可下载指定文件
稿件来源: 阳光企业网站管理系统 撰稿作者: 太阳光 发表日期: 2013-08-23 阅读次数: 354 查看权限: 游客查看
指定网站目录使用FSO生成树形结构,并可下载指定类型文件
使用Fso利用回调函数生成z-tree数据,生成树形结构目录,并指定可下载的文件类型,一般用于文档管理系统里。
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Option Explicit Response.CodePage=65001 Response.Charset="UTF-8" Response.Buffer = True Response.ExpiresAbsolute = Now() - 1 Response.Expires = 0 Response.CacheControl = "no-cache" Response.AddHeader "Pragma", "No-Cache" Dim file_url,fso,s_path,arr_ext,i_folder s_path=Server.MapPath("/FUploadFile") '定义目录树 arr_ext="txt,doc,jpg" '定义可下载文件的类型 '************************************************* '作 用:本程序的作用是直接下载文件而不是在IE中打开,如htm、txt、asp、jpg文件等 '************************************************* file_url=Request.QueryString("file") If file_url<>"" Then 'on error resume Next Dim Scs,ture_url,filename,exe_name,Range,file_name ture_url=server.MapPath(file_url) Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FileExists(ture_url) Then Response.write "<script>alert('对不起,文件不存在!');window.opener=null;window.open('','_self');window.close();</script>" Response.End ElseIf InStr(LCase(ture_url),LCase(s_path)) Then '安全起见,限制只能下载指定目录文件 file_name=Mid(ture_url,instrRev(ture_url,"\")+1) '文件名含后缀 exe_name=Mid(file_name,instrRev(file_name,".")+1)'后缀名 filename=Mid(file_name,1,instrRev(file_name,".")-1)'文件名 Set Scs=CreateObject("Adodb.Stream") Scs.Mode=3 Scs.Type=1 Scs.Open Scs.LoadFromFile(ture_url) If InStr(arr_ext,exe_name)>0 Then Response.ContentType="application/octet-stream" If Instr(Request.ServerVariables("HTTP_USER_AGENT"),"MSIE")>0 Then filename=Server.URLEncode(filename) Response.AddHeader "Content-Disposition:","Attachment;filename="&filename&"."&exe_name Range=Mid(Request.ServerVariables("HTTP_RANGE"),7) If Range="" Then Response.BinaryWrite(Scs.Read) Else Scs.Postion=Clng(Split(Range,"-")(0)) Response.BinaryWrite(Scs.Read) End If Else Response.write "<script>alert('对不起,本文件禁止下载');window.opener=null;window.open('','_self');window.close();</script>" Response.End End If Else Response.write "<script>alert('对不起,你访问了禁区文件!');window.opener=null;window.open('','_self');window.close();</script>" Response.End End If End if '************************************************* '作 用:回调函数,生成z-tree数据 '************************************************* Sub sub_file(TruePath,pid) Dim fso,theFolder,File,Folder,i,this_id If pid<>"0" Then Response.write "," this_id=i_folder+1 Response.write "{id:"""&this_id&""", pId:"&pid&",name:"""&Mid(TruePath,instrRev(TruePath,"\")+1)&"""}" i_folder=i_folder+1 Set fso = CreateObject("Scripting.FileSystemObject") Set theFolder=fso.GetFolder(TruePath) i=1 For Each File In theFolder.Files i=i+1 Response.write ",{id:"""&pid&"_"&i&""", pId:"""&this_id&""",name:"""&Mid(File,instrRev(File,"\")+1)&" ["&File.Size&"KB]"",url:""?file="&Replace(Replace(File,s_path,"/FUploadFile"),"\","/")&"""}" Next For Each Folder In theFolder.subfolders Call sub_file(Folder,this_id) Next Set fso = Nothing End Sub %><!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <TITLE> FSO 生成目录树 scscms</TITLE> <link rel="stylesheet" href="zTreeStyle/zTreeStyle.css" type="text/css"> <script type="text/javascript" src="zTreeStyle/jquery-1.4.4.min.js"></script> <script type="text/javascript" src="zTreeStyle/jquery.ztree.all-3.5.min.js"></script> <script> var zNodes =[<%Call sub_file(s_path,"0")%>]; var setting = {data: {simpleData: {enable: true}}} $(document).ready(function(){ $.fn.zTree.init($("#treeDemo"), setting, zNodes); }); </script> </head> <body> <h2>上传目录浏览</h2> <ul id="treeDemo" class="ztree"></ul> </body> </html>
文件下载:/FUploadFile/files/fso_zTree.rar
关键词: fso,zTree,树形结构 编辑时间: 2013-08-23 20:59:25
0
高兴0
支持0
搞笑0
不解0
谎言0
枪稿0
震惊0
无奈0
无聊0
反对0
愤怒
100%(1)
0%(0)
- 中搜索:FSO生成目录树并可下载指定文件
- 中搜索:FSO生成目录树并可下载指定文件
- 暂无评论
文章图片 article Pictrue
网友评论