<%
' Written by Linzhang Chen, 2003-4-20
' Reprint 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/"' Reference to the 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 ' returns the list of folders below 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,instrrev (fname, ".") +1)) >0 Then ' set the file type to allow return, prevent source 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 is no file in the directory, send an empty element
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 client's JS Kung Fu (selectfile.asp)
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> Select 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
Reprint please specify the source and retain this copyright information * *
Pre-loaded pictures
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";
History 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 ("Please select File First");
return false;
}
Else
{
Window.returnvalue =document.f1.folder.value+document.all.filename.value;
Window.close ();
}
}
Get the contents of an XML file
function getuserlist (URL)
{var oxmldoc = new ActiveXObject (' MSXML ');
Oxmldoc.url = URL;
var ooroot=oxmldoc.root;
return ooroot;
}
When a file is selected, return the value to the text box
function AddFile (TXT)
{
Document.all.filename.value=txt;
}
var first=1;//defines a global variable
function userlist (folders,ti)/list the selected boxes
{document.f1.folder.value=folders;
Filebox.document.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 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 a drop-down box
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 and folders";
Else
{
if (OItem.children.item (0). text== "folder")
{
strshow+= "<tr><td><a href=\" javascript:parent.userlist (' "+folders+oitem.children.item (1). text+"/ "+" ', 1] \ "></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 stacks
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+" ') \ >
}
}
Get the number of columns to 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.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= "><table" width= "409" border= "0" >
<tr>
<TD width= "align=" "right" > Lookup 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= "valign=" "Baseline" id= "Arrow" align=right></td>
<TD width= valign= "Middle" id= "FolderID" ></td>
<TD width= "align=" "left" ></td>
<TD width= "align=" "left" ></td>
</tr>
</table></td>
</tr>
<tr>
<TD height= "><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= "a" > </td>
</tr>
</table></td>
</tr>
<tr>
<TD height= "><table" width= "100%" border= "0" >
<form method=post action= "" Name= "F1" >
<input type= "hidden" name= "folder" Value= "" >
<tr>
<TD width= "align=" "Right" > FileName (<u>N</u>): </td>
<TD width= "254" ><input type= "text" id= "filename" size= "></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's a little file in there. Blank.htm used to define the style of file and folder display
<! 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>
call with the following function, You can implement the effect of a genuine server-side selection file
Function Selectfile ()
{
var arr = ShowModalDialog ("selectfile.asp?temp=" + Math.random (), "", "DIALOGWIDTH:453PX; dialogheight:252px; Status:0;help:1 ");
if (arr!= null)
{
return arr
}
}
& nbsp The function finally returns the selected file name, the function inside the use of a few pictures from the file selection box has been grabbed:)