首先在服務器端先創建一個程序可以生成XML文件,以返回客戶端,(getfolder.asp) <% written by Linzhang Chen ,2003-4-20 轉載請注明出處和保留此版權信息 response.write ""&chr(13) response.write ""&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 ""&chr(13) response.write "folder"&chr(13) response.write ""&fd.name&""&chr(13) response.write ""&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 ""&chr(13) response.write "file"&chr(13) response.write ""&fname&""&chr(13) response.write ""&chr(13) count=count+1 end if next 如果該目錄下沒有文件,就發一個空元素 if count=0 then response.write ""&chr(13) response.write "empty"&chr(13) response.write "0"&chr(13) response.write ""&chr(13) end if response.write "" set ff=nothing set f=nothing set fso=nothing %> 下面就是客戶端的JS的功夫了(selectfile.asp)
選擇視頻文件 查找范圍(I): 文件類型(T): 裡面還有一個小文件blank.htm用來定義文件和文件夾顯示的樣式 New Document 調用的時候用以下函數,就可以實現以假亂真的服務器端選擇文件的效果 function selectfile() { var arr = showModalDialog("selectfile.asp?temp="+Math.random(), "", "dialogWidth:453px; dialogHeight:252px; status:0;help:1"); if (arr != null) { return arr } } 該函數最後返回的是選中的文件名,函數裡面所使用的幾張圖片大家就自已從文件選擇框上抓了:) 估計在使用過程中可能還會遇到各種未知的BUG歡迎大家和我來交流:E_mail:[email protected]