欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用XML+FSO+JS实现服务器端文件的选择

程序员文章站 2023-11-08 14:21:58
首先在服务器端先创建一个程序可以生成xml(标准化越来越近了)文件,以返回客户端,(getfolder.)<%written by linzhang chen ,2003-4...

首先在服务器端先创建一个程序可以生成xml(标准化越来越近了)文件,以返回客户端,(getfolder.)
<%
written by linzhang chen ,2003-4-20
转载请注明出处和保留此版权信息
response.write "<?xml(标准化越来越近了) version=""1.0"" encoding=""gb2312""?>"&chr(13)
response.write "<mediafile>"&chr(13)
folders=request("folder")
if folders="/" then
folders=""
end if
dim count
count=0
folders=replace(folders,"..","")
basefolder="../media/"基准的文件夹路径
newfolder=basefolder&folders
set fso =server.createobject("scripting.filesystemobject")
set f=fso.getfolder(server.mappath(newfolder))
set sf=f.subfolders
for each fd in sf返回指定路径下面的文件夹列表
response.write "<file>"&chr(13)
response.write "<ftype>folder</ftype>"&chr(13)
response.write "<fname>"&fd.name&"</fname>"&chr(13)
response.write "</file>"&chr(13)
count=count+1
next
set sf=nothing
set ff=f.files
for each fi in ff
fname=fi.name
if instr("asf,wma,wmv",lcase(mid(fname,instrrev(fname,".")+1)))>0 then设定允许返回的文件类型,防止泄露
response.write "<file>"&chr(13)
response.write "<ftype>file</ftype>"&chr(13)
response.write "<fname>"&fname&"</fname>"&chr(13)
response.write "</file>"&chr(13)
count=count+1
end if
next
如果该目录下没有文件,就发一个空元素
if count=0 then
response.write "<file>"&chr(13)
response.write "<ftype>empty</ftype>"&chr(13)
response.write "<fname>0</fname>"&chr(13)
response.write "</file>"&chr(13)
end if
response.write "</mediafile>"
set ff=nothing
set f=nothing
set fso=nothing
%>
下面就是客户端的js的功夫了(selectfile.asp)
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> 选择视频文件 </title>
<style>
td{font-size:9pt}
select{width:210}
.s2{width:250}
</style>
<script language="javascript">
<!--
/*written by linzhang chen ,2003-4-20
 转载请注明出处和保留此版权信息 */

//预装载图片
 var imgback = new image();
imgback.src = "images/arrow.gif";
 var imgbackgray = new image();
imgbackgray.src = "images/grayarrow.gif";
 var imgfolder = new image();
imgfolder.src = "images/folder.gif";
 var imggrayfolder = new image();
imggrayfolder.src = "images/grayfolder.gif";
//历史记录数组栈
var arrhistory=new array();
var hisi=0;
//用来确定要返回文件名
function check()
{
if (document.all.filename.value=="")
{
alert("请先选择文件");
return false;
}
else
{
window.returnvalue =document.f1.folder.value+document.all.filename.value;
window.close();
}
}
//取得xml(标准化越来越近了)文件的内容
function getuserlist(url)
{     var oxml(标准化越来越近了)doc = new activexobject(msxml(标准化越来越近了));
    oxml(标准化越来越近了)doc.url = url;
 var ooroot=oxml(标准化越来越近了)doc.root;
return ooroot;
  }
//当选中一个文件时,把这个值返回给文本框
function addfile(txt)
{
document.all.filename.value=txt;
}

var first=1;//定义一个全局变量

function userlist(folders,ti)//列出所选框
{document.f1.folder.value=folders;
filebox.document.body.innerhtml="正在加载文件,请稍侯...";