主頁 > 知識庫 > 用XML+FSO+JS實現(xiàn)服務器端文件的選擇效果

用XML+FSO+JS實現(xiàn)服務器端文件的選擇效果

熱門標簽:vue 地圖標注拖拽 電話機器人銷售公司嗎 保定電銷機器人軟件 客服外呼系統(tǒng)呼叫中心 電話機器人案例 土地證宗地圖標注符號 鎮(zhèn)江云外呼系統(tǒng)怎么樣 成都銷售外呼系統(tǒng)公司 自動外呼系統(tǒng)怎么防止封卡

%
'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=basefolderfolders
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
'如果該目錄下沒有文件,就發(fā)一個空元素
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";
//歷史記錄數(shù)組棧
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;
 //確定歷史狀態(tài)
 hisi+=ti;
 arrhistory[hisi]=folders;
 if (hisi==0)
 {
 arrow.innerHTML="img src=\"images/grayarrow.gif\">";
 }
 else
 {
 arrow.innerHTML="img src=\"images/arrow.gif\" border=0 style=\"cursor:hand\" onclick=\"userlist('"+arrhistory[hisi-1]+"',-1)\" onmouseover=\"this.src='images/arrow_over.gif'\" onmouseout=\"this.src='images/arrow.gif'\">";
 }
 //確定當前的文件夾
 if (document.f1.folder.value=="")
 {
 folderid.innerHTML="img src=\"images/grayfolder.gif\">"
 }
 else
 {newsfolder=checkfolder(document.f1.folder.value)
 folderid.innerHTML="img src=\"images/folder.gif\" border=0 style=\"cursor:hand\" onclick=\"userlist('"+newsfolder+"',1)\" onmouseover=\"this.src='images/folder_over.gif'\" onmouseout=\"this.src='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;iarrfolder.length-1;i++)
  {blankstr+="  ";
  folderstr+=arrfolder[i]+"/";
  _o=document.createElement("Option");
  _o.text=blankstr+arrfolder[i];
  _o.value=folderstr;
  _obj.add(_o);

  }
 }
document.all.select.options[document.all.select.options.length-1].selected=true;
 url="getfolder.asp.gl?folder="+folders;
 oRoot=getuserlist(url)
  strshow="table class=file cellspacing=0 cellpadding=0>";
 len=oRoot.children.length;
 if (len==1)
 {oItem = oRoot.children.item(0);
 if(oItem.children.item(0).text=="empty")
 strshow="沒有文件和文件夾了";
 else
 {
 if(oItem.children.item(0).text=="folder")
   {
   strshow+="tr>td>A href=\"javascript:parent.userlist('"+folders+oItem.children.item(1).text+"/"+"',1)\">img src=\"images/mediafolder.gif\" border=0 >"+oItem.children.item(1).text+"/A>/td>/tr>";
   }
   else
   {
    strshow+="tr>td>a href=\"javascript:parent.addfile('"+oItem.children.item(1).text+"')\" >img src=\"images/mediafile.gif\" border=0>"+oItem.children.item(1).text+"/A>/td>/tr>";

   }
 }
 strshow+="/table>"
 }
 else{
 //數(shù)據(jù)入棧
  for(i=0;ilen;i++)
        {   oItem = oRoot.children.item(i);
   if(oItem.children.item(0).text=="folder")
   {
   arrff[i]="A href=\"javascript:parent.userlist('"+folders+oItem.children.item(1).text+"/"+"',1)\">img src=\"images/mediafolder.gif\" border=0>"+oItem.children.item(1).text+"/A>";
   }
   else
   {
    arrff[i]="A href=\"javascript:parent.addfile('"+oItem.children.item(1).text+"')\">img src=\"images/mediafile.gif\" border=0 height=12>"+oItem.children.item(1).text+"/A>";

   }
  }
     //取得要輸出的列數(shù)
   if (len=6)
   {x=1;
   y=6;}
   else
   {x=len/6;
   y=6;}
   for(var i=0;iy;i++)
   {strshow+="tr>"
   for(var j=0;jx;j++)
   {ponits=j*y+i;
    if (ponits>=len)
    {
    strshow+="td>nbsp;/td>";
    }
    else
    {
    strshow+="td>"+arrff[ponits]+"/td>";
    }
   }
   strshow+="/tr>"
   }

  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>

BODY style="margin:0" bgColor=menu onload="javascript:userlist('',0)">
table width="443" border="0" cellspacing="0">
  tr>
    td height="36">table width="409" border="0">
        tr>
          td width="73" align="right">查找范圍(u>I/u>):/td>
          td width="214">select name="select" id="select" size="1" onchange="javascript:userlist(this.value,1);">
            /select>/td>
          td width="22" valign="baseline" id="arrow" align=right>/td>
          td width="20" valign="middle" id="folderid">/td>
          td width="20" align="left">img src="images/md.gif" width="16" height="15">/td>
          td width="28" align="left">img src="images/viewtype.gif" width="23" height="14">/td>
        /tr>
      /table>/td>
  /tr>
  tr>
    td height="120">table width="100%" height="100%" border="0">
        tr>
          td width="9">nbsp;/td>
          td >
iframe src="blank.htm" width=415 height=120 id="filebox">/iframe>/td>
          td width="13">nbsp;/td>
        /tr>
      /table>/td>
  /tr>
  tr>
    td height="60">table width="100%" border="0">
       FORM METHOD=POST ACTION="" name="f1">
    input type="hidden" name="folder" value="">
         tr>
          td width="85" align="right">文件名(u>N/u>):nbsp;nbsp;/td>
          td width="254">input type="text" id="filename" size="34">/td>
          td>button onclick="javascript:return check()">  打開(u>O/U>)/button>/td>
        /tr>
        /FORM>
        tr>
          td align="right">文件類型(u>T/u>):/td>
          td>select name="select2"   class=s2>
              option>流媒體文件(*.asf,*.wmv,*.wma)/option>
            /select>/td>
          td>input type="button" name="Submit" value=" 取消  " onclick="window.close();">/td>
        /tr>
      /table>/td>
  /tr>
/table>
/BODY>
/HTML>

    里面還有一個小文件blank.htm用來定義文件和文件夾顯示的樣式
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
HTML>
HEAD>
TITLE> New Document /TITLE>
style>
td{font-size:9pt}
body{font-size:9pt}
.file A{COLOR: #000000; TEXT-DECORATION: none;font-size:9pt}
.file A:visited{COLOR: #000000; TEXT-DECORATION: none;font-size:9pt}
.file A:hover {COLOR: #000000; TEXT-DECORATION: none;font-size:9pt}
/style>
/HEAD>

BODY style="margin: 0pt">

/BODY>
/HTML>
     調用的時候用以下函數(shù),就可以實現(xiàn)以假亂真的服務器端選擇文件的效果
function selectfile()
{
var arr = showModalDialog("selectfile.asp?temp="+Math.random(), "", "dialogWidth:453px; dialogHeight:252px; status:0;help:1");
  if (arr != null)
  {
   return arr
  }
}
       該函數(shù)最后返回的是選中的文件名,函數(shù)里面所使用的幾張圖片大家就自已從文件選擇框上抓了:)

標簽:懷化 重慶 內江 公主嶺 天津 麗江 臺灣 成都

巨人網(wǎng)絡通訊聲明:本文標題《用XML+FSO+JS實現(xiàn)服務器端文件的選擇效果》,本文關鍵詞  用,XML+FSO+JS,實現(xiàn),服務器,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《用XML+FSO+JS實現(xiàn)服務器端文件的選擇效果》相關的同類信息!
  • 本頁收集關于用XML+FSO+JS實現(xiàn)服務器端文件的選擇效果的相關信息資訊供網(wǎng)民參考!
  • 推薦文章