<%@ Language=VBscript %>
<%
Response.Buffer=true
On Error Resume Next
Server.ScriptTimeOut = 1000
Response.Expires=0
Dim StartTime,IsReplace
IsReplace = true '是否過濾編輯時(shí)文件的<textarea></textarea>標(biāo)記,如不過濾遇到有<textarea>標(biāo)記的文件時(shí)編輯有顯示不完全的現(xiàn)象
StatrTime = Timer()
%>
<%
'****************************************
'函數(shù)定義部分開始
'****************************************
'*******************************************
'過程作用:判斷服務(wù)器是否支持FSO
'*******************************************
Sub IsErr()
If Err = -2147221005 Then
Response.write "這臺服務(wù)器不支持FSO,故本程序無法運(yùn)行"
Response.end
End If
End Sub
'*******************************************
'函數(shù)作用:取得文件的后綴名
'*******************************************
Function UpDir(ByVal D)
Dim UDir
If Len(D) = 0 then Exit Function
UDir=Left(D,InStrRev(D,"\")-1)
UpDir=UDir
End Function
'*******************************************
'函數(shù)作用:取得當(dāng)前頁的URL,
' 為文件添加正確的鏈接
'*******************************************
Function FileUrl(url,D)
Dim PageUrl,PUrl
PageUrl="http://"& Request.ServerVariables("SERVER_NAME")
PUrl=Left(Request.ServerVariables("URL"),InStrRev(Request.ServerVariables("Url"),"/"))
PageUrl=PageUrl & Purl & Mid(D,2,Len(D)) & "/" & url
FileUrl=PageUrl
End Function
'*******************************************
'函數(shù)作用:格式化文件的大小
'*******************************************
Function GetFileSize(size)
Dim FileSize
FileSize=size / 1024
FileSize=FormatNumber(FileSize,2)
If FileSize < 1024 and FileSize > 1 then
GetFileSize="<font color=red>"& FileSize & "</font> KB"
ElseIf FileSize >1024 then
GetFileSize="<font color=red>"& FormatNumber(FileSize / 1024,2) & "</font> MB"
Else
GetFileSize="<font color=red>"& Size & "</font> Bytes"
End If
End Function
'*******************************************
'函數(shù)作用:取得文件的后綴名
'*******************************************
Function GetExtensionName(name)
Dim FileName
FileName=Split(name,".")
GetExtensionName=FileName(Ubound(FileName))
End Function
'*******************************************
'函數(shù)作用:返回文件類型
'*******************************************
Function GetFileIcon(name)
Dim FileName,Icon
FileName=Lcase(GetExtensionName(name))
Select Case FileName
Case "asp"
Icon = "asp"
Case "bmp"
Icon = "bmp"
Case "doc"
Icon = "doc"
Case "exe"
Icon = "exe"
Case "gif"
Icon = "gif"
Case "jpg"
Icon = "jpg"
Case "chm"
Icon = "chm"
Case "htm","html"
Icon = "htm"
Case "log"
Icon = "log"
Case "mdb"
Icon = "mdb"
Case "swf"
Icon = "swf"
Case "txt"
Icon = "txt"
Case "wav"
Icon = "wav"
Case "xls"
Icon = "xls"
Case "rar","zip"
Icon = "zip"
Case "css"
Icon = "css"
Case Else
Icon = "none"
End Select
GetFileIcon=Icon
End Function
'*******************************************
'過程作用:刪除選定的文件或文件夾
'*******************************************
Sub DelAll()
Dim FolderId,FileId,ThisDir,FileNum,FolderNum,FilePath,FolderPath
FolderId = Split(Request.Form("FolderId"),",")
FileId = Split(Request.Form("FileId"),",")
ThisDir = trim(Request.Form("ThisDir"))
FileNum=0
FolderNum=0
If Ubound(FolderId) <> -1 then '刪除文件夾
For i = 0 to Ubound(FolderId)
FolderPath = Server.MapPath(".") & ThisDir & "\" & trim(FolderId(i))
If Fso.FolderExists(FolderPath) then
Fso.DeleteFolder FolderPath,true
FolderNum = FolderNum + 1
End If
Next
End If
If Ubound(FileId) <> -1 then '刪除文件
For j = 0 to Ubound(FileId)
FilePath = Server.MapPath(".") & ThisDir & "\" & trim(FileId(j))
If Fso.FileExists(FilePath) then
Fso.DeleteFile FilePath,true
FileNum = FileNum + 1
End If
Next
End If
Response.write "<script>alert('\n恭喜,刪除成功\n\n"& FolderNum &" 個(gè)文件夾被刪除\n"& FileNum &" 個(gè)文件被刪除');window.location.href=('"& Replace(Request.ServerVariables("HTTP_REFERER"),"\","\\") &"')</script>"
End Sub
'*******************************************
'過程作用:使選定的文件或文件夾改名
'*******************************************
Sub Rname()
Dim ThisDir,FolderName,NewName,OldName
ThisDir = Trim(Request.Form("ThisDir"))
FolderName = Trim(Request.Form("FolderId"))
FileName = Trim(Request.Form("FileId"))
NewName = Trim(Request.QueryString("NewName"))
If len(FolderName) <> 0 then '文件夾改名
NewName1 = Server.MapPath(".") & ThisDir & "\" & NewName
OldName = Server.MapPath(".") & ThisDir & "\" & FolderName
If not Fso.FolderExists(NewName1) then
Fso.MoveFolder OldName,NewName1
Response.write "<script>alert('【 "& FolderName &" 】文件夾已經(jīng)成功改名為【 "& NewName &" 】');window.location.href=('"& Replace(Request.ServerVariables("HTTP_REFERER"),"\","\\") &"')</script>"
Else
Response.write "<script>alert('有同名文件夾,請換個(gè)文件夾名');window.location.href=('"& Replace(Request.ServerVariables("HTTP_REFERER"),"\","\\") &"')</script>"
End If
End If
If len(FileName) <> 0 then '文件改名
NewName1 = Server.MapPath(".") & ThisDir & "\" & NewName
OldName = Server.MapPath(".") & ThisDir & "\" & FileName
If not Fso.FileExists(NewName1) then
Fso.MoveFile OldName,NewName1
Response.write "<script>alert('【 "& FileName &" 】文件已經(jīng)成功改名【 "& NewName &" 】');window.location.href=('"& Replace(Request.ServerVariables("HTTP_REFERER"),"\","\\") &"')</script>"
Else
Response.write "<script>alert('有同名文件,請換個(gè)文件名');window.location.href=('"& Replace(Request.ServerVariables("HTTP_REFERER"),"\","\\") &"')</script>"
End If
End If
End Sub
'*******************************************
'過程作用:新建文件
'*******************************************
Sub NewFile()
Dim NewFile,NewFilePath
NewFilePath = Trim(Request.Form("ThisDir"))
NewFile = Trim(Request.Form("NewFileName"))
NewFilePath = Server.MapPath(".") & NewFilePath & "\" & NewFile
If not Fso.FileExists(NewFilePath) and not Fso.FolderExists(NewFilePath) then
Set FsoFile = Fso.CreateTextFile(NewFilePath)
FsoFile.Writeline
FsoFile.close
Set FsoFile = nothing
Response.write "<script>alert('建立文件成功');window.location.href=('"& Replace(Request.ServerVariables("HTTP_REFERER"),"\","\\") &"')</script>"
Else
Response.write "<script>alert('有同名文件,請換個(gè)文件名');window.location.href=('"& Replace(Request.ServerVariables("HTTP_REFERER"),"\","\\") &"')</script>"
End if
End Sub
'*******************************************
'過程作用:新建文件夾
'*******************************************
Sub NewFolder()
Dim NewFolder,NewFolderPath
NewFolderPath = Trim(Request.Form("ThisDir"))
NewFolder = Trim(Request.Form("NewFolderName"))
NewFolderPath = Server.MapPath(".") & NewFolderPath & "\" & NewFolder
If not Fso.FolderExists(NewFolderPath) then
Fso.CreateFolder(NewFolderPath)
Response.write "<script>alert('建立文件夾成功');window.location.href=('"& Replace(Request.ServerVariables("HTTP_REFERER"),"\","\\") &"')</script>"
Else
Response.write "<script>alert('有同名文件夾,請換個(gè)文件夾名');window.location.href=('"& Replace(Request.ServerVariables("HTTP_REFERER"),"\","\\") &"')</script>"
End if
End Sub
'*******************************************
'過程作用:css 樣式
'*******************************************
Sub Css()
%>
<style>
.fonts{font-size:9pt;line-height:25px}
.button{padding:2px;
height:20px;
background-color:#FF9900;
color:#ffffff;
border:1px solid #333333;
font-size:12px;
font-family: "宋體";
}
.TextBox {
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #666666;
border-right-color: #CCCCCC;
border-bottom-color: #CCCCCC;
border-left-color: #666666;
padding: 2px;
height: 300px;
font-size:12px;
font-family: "宋體";
}
.InputBox {
border-top-width:1px;
border-left-width:1px;
border-right-width:1px;
border-bottom-width:1px;
border-top-color:#000000;
border-left-color:#000000;
border-bottom-color:#000000;
border-right-color:#000000;
padding:2px;
height:20px;
}
Input, Select, TextArea {
font-family: "宋體";
font-size: 12px;
text-decoration: none;
}
a:link { color: #000000; text-decoration: none}
a:visited { color: #000000; text-decoration: none}
a:hover { color: #FF0000; text-decoration: underline}
</style>
<%
End Sub
'*******************************************
'過程作用:編輯文件
'*******************************************
Sub Edit()
Dim FilePath,FileName,action
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
IsErr
action=Trim(Request.QueryString("action"))
If action = ("Save") then '保存文件
Dim FileSave
FilePath = trim(Request.QueryString("FilePath"))
FileAll = trim(Request.Form("FileAll"))
If IsReplace then FileAll = Replace(FileAll,"\\textarea\\","textarea")
If Fso.FileExists(FilePath) then
Set FileSave = Fso.OpenTextFile(FilePath,2)
FileSave.Write(FileAll)
FileSave.Close
Response.write "<script>if(confirm('文件已經(jīng)保存,是否關(guān)閉本頁')){window.close();}else{history.back();}</script>"
Else
Response.write "<script>alert('發(fā)生錯(cuò)誤,文件已經(jīng)被刪除或者損壞!');window.close()</script>"
End If
ElseIf action = ("Edit") then '讀取文件
Dim FileAll
FilePath = Trim(Request.Form("ThisDir"))
FileName = Trim(Request.Form("FileId"))
FilePath1 = Server.MapPath(".") & FilePath & "\" & FileName
If Fso.FileExists(FilePath1) then
Set FileOpen = Fso.OpenTextFile (FilePath1,1)
FileAll = FileOpen.ReadAll
FileOpen.close
If IsReplace then FileAll = Replace(FileAll,"textarea","\\textarea\\")
Else
Response.write "<script>alert('發(fā)生錯(cuò)誤,文件已經(jīng)被刪除或者損壞!');window.close()</script>"
End If
%>
<html>
<head>
<title>FSO在線編輯</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<% Call Css %>
<script language=javascript>
function Check()
{
if(confirm("確定要保存文件么?\n此操作不可恢復(fù)!")){
return true;
}
else{
return false;
}
}
</script></head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<form name="form" method="post" action="?action=Save&FilePath=<%=Server.MapPath(".") & FilePath & "\" & Filename %>" onSubMit="return Check()">
<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center" class="fonts">
<tr>
<td> </td>
</tr>
<tr>
<td>系統(tǒng)主目錄:<a href=?action=Open&Dir= title=返回到系統(tǒng)主目錄><font color=FF6600><b><%=Server.MapPath(".")%></b></font></a></td>
</tr>
<tr>
<td bgcolor="B7CECD" height="1"></td>
</tr>
<tr>
<td height="20" valign="bottom"> 當(dāng)前目錄:<%=Server.MapPath(".") & FilePath %></td>
</tr>
<tr>
<td bgcolor="B7CECD" height="1"></td>
</tr>
<tr>
<td height="30" valign="middle"> 文件名: <font color=red><b><%=FileName%></b></font>
<select name="select" onChange="FileAll.style.fontSize=this.options[this.options.selectedIndex].value">
<option selected value="12px">字體大小</option>
<option value="12px">12px</option>
<option value="14px">14px</option>
<option value="16px">16px</option>
</select>
<select name="select2" onChange="FileAll.style.color=this.options[selectedIndex].value">
<option selected value="#000000">顏色</option>
<option value="#666666">灰色</option>
<option value="#ff0000">紅色</option>
<option value="#087100">綠色</option>
</select>
</td>
</tr>
<tr>
<td bgcolor="B7CECD" height="1" id="a11"></td>
</tr>
<tr>
<td><table cellpadding=3 cellspac=0 class=fonts><tr><td>
<textarea id="FileAll" name="FileAll" cols="100" rows="20" class=textbox style="word-break: break-all; width: 700px; height: 380px;"><%=FileAll%></textarea>
</td><tr><td height=0></td></tr><tr><td>
<input type="submit" name="Submit" value=" 保存文件 " class=button>
<input type="reset" name="Submit2" value=" 撤消修改 " class=button>
<input type="button" name="Submit3" value=" 關(guān)閉窗口 " class=button onClick="window.close()">
</td></tr></table><br>
</td>
</tr>
</table>
</form>
</body>
</html>
<%
End If
Set Fso = nothing
End Sub
'****************************************
'函數(shù)定義部分結(jié)束
'****************************************
%>
<%
Dim Fso,FsoFile,FileType,FileSize,FileTime,Path
Dim Dir
action=Trim(Request.QueryString("action"))
Set Fso=Server.CreateObject("Scripting.FileSystemObject")
IsErr
If action = "Del" then
Call DelAll
ElseIf action = "NewFile" then
Call NewFile
ElseIf action = "NewFolder" then
Call NewFolder
ElseIf action = "Rname" then
Call Rname
ElseIf action = "Edit" then
Call Edit
ElseIf action = "Save" then
Call Edit
Else
Dir=Trim(Request.QueryString("Dir"))
Path = Server.MapPath(".") & Dir
Set FsoFile = Fso.GetFolder(Server.MapPath("."))
FsoFileSize = FsoFile.size '空間大小統(tǒng)計(jì)
Set FsoFile = nothing
Set FsoFile = Fso.GetFolder(Path)
%>
<html>
<head>
<title>FSO在線編輯</title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<% Call Css %>
<script language=javascript>
function Checked()
{
var j = 0
for(i=0;i < document.form.elements.length;i++){
if(document.form.elements[i].name == "FileId" || document.form.elements[i].name == "FolderId"){
if(document.form.elements[i].checked){
j++;
}
}
}
return j;
}
function CheckAll1()
{
for(i=0;i<document.form.elements.length;i++)
{
if(document.form.elements[i].checked){
document.form.elements[i].checked=false;
document.form.CheckAll.checked=false;
}
else{
document.form.elements[i].checked = true;
document.form.CheckAll.checked = true;
}
}
}
function DelAll()
{
if(Checked() <= 0){
alert("您必須選擇其中的一個(gè)文件或文件夾");
}
else{
if(confirm("確定要?jiǎng)h除選擇的文件或文件夾么?\n此操作不可以恢復(fù)!")){
form.action="?action=Del";
form.submit();
}
}
}
function Edit()
{
if(Checked() == 0){
alert("您必須選擇其中的一個(gè)文件");
}
else{
if(Checked() != 1){
alert("只能選擇一個(gè)文件(文本文件)");
}
else{
for(i=0;i < document.form.elements.length;i++){
if(document.form.elements[i].name == "FileId" && document.form.elements[i].checked){
form.action="?action=Edit";
form.target="self";
form.submit();
break;
}
else if(document.form.elements[i].name == "FolderId" && document.form.elements[i].checked){
alert("不能編輯文件夾")
break;
}
}
}
}
}
function Rname()
{
if(Checked() == 0){
alert("您必須選擇一個(gè)文件或文件夾");
}
else{
if(Checked() != 1){
alert("只能選擇一個(gè)文件或一個(gè)文件夾");
}
else{
for(i=0;i < document.form.elements.length;i++){
if(document.form.elements[i].name == "FolderId" && document.form.elements[i].checked){
var j = prompt("請輸入新文件夾名",document.form.elements[i].value)
break;
}
else if(document.form.elements[i].name == "FileId" && document.form.elements[i].checked){
var j = prompt("請輸入新文件名",document.form.elements[i].value)
break;
}
}
if(j != "" && j != null){
if(IsStr(j) == j.length){
form.action="?action=Rname&NewName=" + j;
form.target="_self";
form.submit();
}
else{
alert("新名稱不符合標(biāo)準(zhǔn),只能是字母、數(shù)字、點(diǎn)和下劃線的組合,\n不能含有漢字、空格和其他符號");
}
}
}
}
}
function IsStr(w)
{
var str = "abcdefghijklmnopqrstuvwxyz_1234567890."
w = w.toLowerCase();
var j = 0;
for(i=0;i < w.length;i++){
if(str.indexOf(w.substr(i,1)) != -1){
j++;
}
}
return j;
}
function NewFile(form,i)
{
if(i == 1){
if(form.NewFolderName.value == ""){
alert("文件夾名不能為空");
}
else{
if(IsStr(form.NewFolderName.value) == form.NewFolderName.value.length){
form.action="?action=NewFolder";
form.submit();
}
else{
alert("文件夾名不符合標(biāo)準(zhǔn),只能是字母、數(shù)字、點(diǎn)和下劃線的組合,\n不能含有漢字、空格和其他符號");
}
}
}
else{
if(form.NewFileName.value == ""){
alert("文件名不能為空");
}
else{
if(IsStr(form.NewFileName.value) == form.NewFileName.value.length){
form.action="?action=NewFile";
form.submit();
}
else{
alert("文件名不符合標(biāo)準(zhǔn),只能是字母、數(shù)字、點(diǎn)和下劃線的組合,\n不能含有漢字、空格和其他符號");
}
}
}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center" class="fonts">
<tr>
<td> </td>
</tr>
<tr>
<td>系統(tǒng)主目錄:<a href="?action=Open&Dir=" title="返回到系統(tǒng)主目錄"><font color=FF6600><b><%=Server.MapPath(".")%></b></font></a> 空間占用:<%=GetFileSize(FsoFileSize)%></td>
</tr>
<tr>
<td bgcolor="B7CECD" height="1"></td>
</tr>
<tr>
<td height="20" valign=bottom> <a href=?action=Open&Dir=<%=UpDir(Dir)%>>返回到上一目錄</a> 當(dāng)前目錄:<%=Server.MapPath(".") & Dir %><br> 占用空間:<%=GetFileSize(FsoFile.size)%> 其中包含 <font color=red><%=FsoFile.SubFolders.count%></font> 個(gè)文件夾; <font color=red><%=FsoFile.Files.count%></font> 個(gè)文件</td>
</tr>
<tr>
<td bgcolor="B7CECD" height="1"></td>
</tr>
<form name="form1" method="post">
<tr>
<td height="60" valign="middle"> 新建文件夾:
<input type="text" name="NewFolderName" size="15" class=InputBox title=在當(dāng)前目錄下新建文件夾 maxlength="50">
<input type="button" name="Submit4" value="新建文件夾" class=button style="cursor:hand" title=新建文件夾 onClick="NewFile(this.form,1)">
<font color="990033">
<input type="hidden" name="ThisDir" value="<%=Dir%>">
</font><br>
新建文件:
<input type="text" name="NewFileName" size="15" class=InputBox title=在當(dāng)前目錄下新建文件 maxlength="50">
<input type="button" name="Submit5" value=" 新建文件 " class=button style="cursor:hand" title=新建文件 onClick="NewFile(this.form,2)">
</td>
</tr>
</form>
<tr>
<td valign="top">
<table width="85%" border="0" cellspacing="1" cellpadding="0" bgcolor="B4E2EF" class="fonts">
<form name="form" method="post" >
<tr bgcolor="F4F4F4">
<Td width="6%" align="center"> </td>
<td width="39%"><font color="990033"> 文件/文件夾名 </font></td>
<td width="13%" align="center"><font color="990033">類型</font></td>
<td width="15%" align="center"><font color="990033">文件大小</font></td>
<td width="27%" align="center"><font color="990033">最后修改時(shí)間</font></td>
</tr>
<%
For Each DirFolder in FsoFile.SubFolders
FolderName=DirFolder.name
FolderSize=GetFileSize(DirFolder.size)
FolderTime=DirFolder.DateLastModified
%>
<tr bgcolor="#FFFFFF">
<td width="6%" align="center">
<input type="checkbox" name="FolderId" value="<%=FolderName%>">
</td>
<td width="39%"> <a href=?action=Open&Dir=<%=Dir%>\<%=FolderName%>><%=FolderName%></a></td>
<td width="13%" align="center">文件夾</td>
<td width="15%" align="center"><%=FolderSize%></td>
<td width="27%" align="center"><%=FolderTime%></td>
</tr>
<% Next %>
<%
For Each DirFiles in FsoFile.Files
FileName=DirFiles.name
FileType=GetFileIcon(FileName)
FileSize=GetFileSize(DirFiles.size)
FileTime=DirFiles.DateLastModified
%>
<tr bgcolor="#FFFFFF">
<td width="6%" align="center">
<input type="checkbox" name="FileId" value="<%=FileName%>">
</td>
<td width="39%"> <a href=<%=FileUrl(FileName,Dir)%> target=_blank><%=FileName%></a></td>
<td width="13%" align="center"><%=FileType%>文件</td>
<td width="15%" align="center"><%=FileSize%></td>
<td width="27%" align="center"><%=FileTime%></td>
</tr>
<% Next %>
<tr bgcolor="#FFFFFF">
<td width="6%" align="center">
<input type="checkbox" name="CheckAll" value="checkbox" onClick="CheckAll1()" title=全部選擇 style="cursor:hand">
</td>
<td colspan="4" height="30">
<input type="button" name="Submit" value="編 輯" class=button style="cursor:hand" onClick="Edit()" title=編輯>
<input type="button" name="Submit2" value="刪 除" class=button style="cursor:hand" onClick="DelAll()" title=刪除>
<input type="button" name="Submit3" value="重命名" class=button style="cursor:hand" onClick="Rname()" title=重命名>
<font color="990033">
<input type="hidden" name="ThisDir" value="<%=Dir%>">
</font> </td>
</tr>
</form>
</table>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td bgcolor="B7CECD" height="1"></td>
</tr>
<tr>
<td height="20" align="center"> 程序制作:<a href="mailto:likaiabc@163.com">阿賽工作室</a> 程序運(yùn)行時(shí)間:<font color=red><%=FormatNumber((Timer()-StatrTime)*1000,3) %></font> 毫秒</td>
</tr>
<tr>
<td bgcolor="B7CECD" height="1"></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
<% End If
Set FsoFile = nothing
Set Fso = nothing
%>