Use XML + FSO + JS to implement

Source: Internet
Author: User

First, create a program on the server to generate an XML file to return to the client, (getfolder. asp)

<%

'Written by Linzhang Chen, 2003-4-20

'Reprinted please indicate the source and retain this copyright information

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/" 'baseline folder path

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, return to the folder list under the specified path

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, Rev (fname ,". ") + 1)> 0 then': Specifies the file type to be returned to prevent source code leakage.

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 there are no files in this directory, an empty element will be sent.

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

%>

The following is the JS effort of the client (selectfile. asp)

<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">

<HTML>

<HEAD>

<TITLE> select a video file </TITLE>

<Style>

Td {font-size: 9pt}

Select {width: 210}

. S2 {width: 250}

</Style>

<Script language = "javascript">

<! --

/* Written by Linzhang Chen, 2003-4-20

Reprinted, please indicate the source and retain this copyright information */

// Preload the image

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 ";

// Record array Stack

Var arrhistory = new Array ();

Var hisi = 0;

// Used to determine the file name to return

Function check ()

{

If (document. all. filename. value = "")

{

Alert ("select a file first ");

Return false;

}

Else

{

Window. returnValue = document. f1.folder. value + document. all. filename. value;

Window. close ();

}

}

// Get the content of the XML file

Function getuserlist (url)

{Var oXMLDoc = new ActiveXObject ('msxml ');

OXMLDoc. url = url;

Var ooRoot = oXMLDoc. root;

Return ooRoot;

}

// Return this value to the text box when a file is selected

Function addfile (txt)

{

Document. all. filename. value = txt;

}

Var first = 1; // defines a global variable.

Function userlist (folders, ti) // lists the selected boxes

{Document. f1.folder. value = folders;

Filebox.doc ument. body. innerHTML = "loading file. Please wait ...";

Var strshow = "";

Var timeoutid = null;

Var newfolder = "";

Var arrfolder = new Array ();

Var arrff = new Array ();

Var blankstr = "";

Var oItem;

// Determine the Historical Status

Hisi + = ti;

Arrhistory [hisi] = folders;

If (hisi = 0)

{

Arrow. innerHTML = " ";

}

Else

{

Arrow. innerHTML = " ";

}

// Determine the current folder

If (document. f1.folder. value = "")

{

Folderid. innerHTML = "
}

Else

{Newsfolder = checkfolder (document. f1.folder. value)

Folderid. innerHTML = "
}

// Assign a value to the drop-down list

Document. all. select. options. length = 0;

Newfolder = folders;

Folderstr = ""

Var _ obj = document. all. select;

Var _ o = document. createElement ("Option ");

_ O. text = "select folder ";

_ 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 );

}

}

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 = "no files or folders ";

Else

{

If (oItem. children. item (0). text = "folder ")

{

Strshow + = "<tr> <td> <A href = \" javascript: parent. userlist ('"+ folders + oItem. children. item (1 ). text + "/" + "', 1) \"> "+ oItem. children. item (1 ). text + "</A> </td> </tr> ";

}

Else

{

Strshow + = "<tr> <td> <a href = \" javascript: parent. addfile ('"+ oItem. children. item (1 ). text + "') \"> "+ oItem. children. item (1 ). text + "</A> </td> </tr> ";

}

}

Strshow + = "</table>"

}

Else {

// Data into the stack

For (I = 0; I <len; 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) \"> "+ oItem. children. item (1 ). text + "</A> ";

}

Else

{

Arrff [I] = "<A href = \" javascript: parent. addfile ('"+ oItem. children. item (1 ). text + "') \"> "+ oItem. children. item (1 ). text + "</A> ";

}

}

// Obtain the number of columns to be output

If (len <= 6)

{X = 1;

Y = 6 ;}

Else

{X = len/6;

Y = 6 ;}

For (var I = 0; I <y; I ++)

{Strshow + = "<tr>"

For (var j = 0; j <x; j ++)

{Ponits = j * y + I;

If (ponits> = len)

{

Strshow + = "<td> </td> ";

}

Else

{

Strshow + = "<td>" + arrff [ponits] + "</td> ";

}

}

Strshow + = "</tr>"

}

Strshow + = "</table>"

}

Filebox.doc ument. body. innerHTML = strshow;

}

// -->

</SCRIPT>

<Script LANGUAGE = "vbscript">

Function checkfolder (folderstr)

If (folderstr = "" or instr (folderstr, "/") = faster Rev (folderstr, "/") then

Checkfolder = ""

Else

Nfolder = left (folderstr, len (folderstr)-1)

Checkfolder = left (nfolder, limit Rev (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"> search range (<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"> </td>

<Td width = "28" align = "left"> </td>

</Tr>

</Table> </td>

</Tr>

<Tr>

<Td height = "120"> <table width = "100%" height = "100%" border = "0">

<Tr>

<Td width = "9"> </td>

<Td>

<Iframe src = "blank.htm" width = 415 height = 120 id = "filebox"> </iframe> </td>

<Td width = "13"> </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"> file name (<u> N </u>): </td>

<Td width = "254"> <input type = "text" id = "filename" size = "34"> </td>

<Td> <button onclick = "javascript: return check ()"> open (<u> O </U>) </button> </td>

</Tr>

</FORM>

<Tr>

<Td align = "right"> file type (<u> T </u>): </td>

<Td> <select name = "select2" class = s2>

<Option> streaming media files (*. asf, *. wmv, *. wma) </option>

</Select> </td>

<Td> <input type = "button" name = "Submit" value = "cancel" onclick = "window. close ();"> </td>

</Tr>

</Table> </td>

</Tr>

</Table>

</BODY>

</HTML>

There is also a small file named "blank.htm" to define the display style of files and folders.

<! 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>

You can use the following functions to select files on the server.

Function selectfile ()

{

Var arr = showModalDialog ("selectfile. asp? Temp = "+ Math. random ()," "," dialogWidth: pixel PX; dialogHeight: 252px; status: 0; help: 1 ");

If (arr! = Null)

{

Return arr

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.