用XML+FSO+JS實現伺服器端檔案的

來源:互聯網
上載者:User
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/a/o/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 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/a/o/images/arrow.gif\" border=0 style=\"cursor:hand\" onclick=\"userlist('"+arrhistory[hisi-1]+"',-1)\" onmouseover=\"this.src='http://www.163design.net/a/o/images/arrow_over.gif'\" onmouseout=\"this.src='http://www.163design.net/a/o/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)



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。