标题: PHP网页编程之用XML+FSO+JS完成办事器端文件 [打印本页] 作者: 爱飞 时间: 2015-2-16 00:28 标题: PHP网页编程之用XML+FSO+JS完成办事器端文件 基础这个东西是个比较笼统的概念,如果你之前学习过c语言, c语言被认为是fso|js|xml|办事器 起首在办事器端先创立一个法式可以生成XML文件,以前往客户端,(getfolder.asp)
<%
'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 = "http://www.163design.net/p/a/images/arrow.gif";
var imgbackgray = new Image();
imgbackgray.src = "images/grayarrow.gif";
var imgfolder = new Image();
imgfolder.src = "http://www.163design.net/p/a/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 oXMLDoc = new ActiveXObject('MSXML');
oXMLDoc.url = url;
var ooRoot=oXMLDoc.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="正在加载文件,请稍侯...";
var strshow="";
var timeoutid=null;
var newfolder="";
var arrfolder=new Array();
var arrff=new Array();
var blankstr="";
var oItem;
//肯定汗青形态
hisi+=ti;
arrhistory[hisi]=folders;
if (hisi==0)
{
arrow.innerHTML="<img src=http://www.163design.net/"images/grayarrow.gif\">";
}
else
{
arrow.innerHTML="<img src=http://www.163design.net/"http://www.163design.net/p/a/images/arrow.gif\" border=0 style=\"cursor:hand\" onclick=\"userlist('"+arrhistory[hisi-1]+"',-1)\" onmou搜索引擎优化ver=\"this.src='http://www.163design.net/p/a/images/arrow_over.gif'\" onmou搜索引擎优化ut=\"this.src='http://www.163design.net/p/a/images/arrow.gif'\">";
}
//肯定以后的文件夹
if (document.f1.folder.value=="")
{
folderid.innerHTML="<img src=http://www.163design.net/"images/grayfolder.gif\">"
}
else
{newsfolder=checkfolder(document.f1.folder.value)
folderid.innerHTML="<img src=http://www.163design.net/"http://www.163design.net/p/a/images/folder.gif\" border=0 style=\"cursor:hand\" onclick=\"userlist('"+newsfolder+"',1)\" onmou搜索引擎优化ver=\"this.src='http://www.163design.net/p/a/images/folder_over.gif'\" onmou搜索引擎优化ut=\"this.src='http://www.163design.net/p/a/images/folder.gif'\">"
}
//给下拉框赋值
document.all.select.options.length=0;
newfolder=folders;
folderstr=""
var _obj=document.all.select;
var _o=document.createElement("Option");
_o.text="选择文件夹";
_o.value="";
_obj.add(_o);
if (newfolder!="")
{arrfolder=newfolder.split("/")
for(var i=0;i<arrfolder.length-1;i++)
{blankstr+=" ";
folderstr+=arrfolder[i]+"/";
_o=document.createElement("Option");
_o.text=blankstr+arrfolder[i];
_o.value=folderstr;
_obj.add(_o);
strshow+="</table>"
}
filebox.document.body.innerHTML=strshow;
}
//-->
</SCRIPT>
<script LANGUAGE="vbscript">
function checkfolder(folderstr)
if (folderstr="" or instr(folderstr,"/")=instrrev(folderstr,"/")) then
checkfolder=""
else
nfolder=left(folderstr,len(folderstr)-1)
checkfolder=left(nfolder,instrrev(nfolder,"/"))
end if
end function
</script>
</HEAD>