<%
'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 );
}< BR >}< br> document. all. select. options [document. all. select. options. length-1]. selected = true;
url = "getfolder. ASP. gl? Folder = "+ folders;
oroot = getuserlist (URL)
strshow ="
}< BR >}< br> strshow + = ""
}< br> else {
// data stack entry
for (I = 0; I {oitem = oroot. children. item (I);
If (oitem. children. item (0 ). TEXT = "folder")
{< br> arrff [I] = " "+ oitem. children. item (1 ). text + "";
}< br> else
{< br> arrff [I] = " "+ oitem. children. item (1 ). text + "";
}
}
// 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
}
}
The selected file name is returned at the end of the function. You have captured several images in the function from the file selection box :)