2001년도쯤에 작성한걸로 기억하는 코드인데 괴상한 목적으로 사용하지 않는게 좋고 관리를 목적으로 사용하려면 security validation정도는 해주시는 센스필요하구요. 잘 응용하고 파일전송을 안정적으로 할 수 있는 application을 개발하시면 웹하드 용도로도 괜찮을 것 같은데. 그냥 생각일 뿐입니다.
<%@ language=vbscript %>
<%
option explicit
On Error Resume Next
dim command
command = request.querystring("command")
select case command
case "drives"
call drivelist
case "folders"
call folderlist
case "viewfile"
call viewfile
case "downfile"
call downfile
case "delfile"
call delFile
case "editfile"
call editFile
case "upload"
call upload
case "copyfile"
call copyfile
case "movefile"
call movefile
case "pastefile"
call pastefile
case "dumplist"
call dumplist
case else
call drivelist
end select
if err.description <> "" then
response.clear
response.write "<script language=javascript> alert (""" & err.description & """); history.back();</script>"
err.clear
end if
Function CalcByte(xspace)
If xspace < 1024 Then
CalcByte = xspace
ElseIf xspace >= 1024 And xspace < 1048576 Then
CalcByte = FormatNumber((xspace / 1024),2) & " K"
ElseIf xspace >= 1048576 And xspace < 1073741824 Then
CalcByte = FormatNumber((xspace / 1048576),2) & " M"
ElseIf xspace >= 1073741824 then
CalcByte = FormatNumber((xspace/1073741824),2) & "G"
End If
End Function
Function FileAttributes(intAttribute)
select case intAttribute
case 0
FileAttributes = "Normal"
case 1
FileAttributes = "Read Only"
case 2
FileAttributes = "Hidden"
case 4
FileAttributes = "System"
case 16
FileAttributes = "Directory"
case 32
FileAttributes = "Archive"
case 1024
FileAttributes = "Alias"
case 2048
FileAttributes = "Compressed"
case else
FileAttributes = intAttribute
end select
End Function
Function xLeft(strTemp, intPoint)
if Len(strTemp) <= intPoint then
xLeft = strTemp
else
xLeft = mid(strTemp,1, intPoint) & "..."
end if
End Function
Function FileExists(strFilename)
Dim FSO
Set FSO = server.createobject("Scripting.FileSystemObject")
FileExists = FSO.FileExists(strFilename)
Set FSO = Nothing
End Function
Sub goBack(Msg)
response.clear
response.write "<html><body><form action=""" & request.servervariables("HTTP_REFERER") & """ method=post name=form1></form>"
response.write "<script language=javascript>"
if Msg <> "" then
response.write " alert (""" & Msg & """);"
end if
response.write " document.form1.submit();</script>"
response.write "</body></html>"
if err.description = "" then
response.end
end if
End Sub
Sub drivelist
dim fso
dim objDrive
dim drivetype(5)
dim strDriveTypeImg
dim strDriveLetter
dim strDriveName
dim intFreeSpace
dim intTotalSpace
drivetype(0) = "알 수 없음"
drivetype(1) = "<img src=""images/drivetype1.jpg"">"
drivetype(2) = "<img src=""images/drivetype2.jpg"">"
drivetype(3) = "<img src=""images/drivetype3.jpg"">"
drivetype(4) = "<img src=""images/drivetype4.jpg"">"
drivetype(5) = "RAM"
set fso = server.createobject("scripting.filesystemobject")
response.write "<table border=0 cellpadding=5 cellspacing=1 bgcolor=black align=center width=95% >"
response.write "<tr bgcolor=#eeeeee align=center><td>종류</td><td>드라이브 이름</td><td>공간(빈/총)</td></tr>"
for each objDrive in fso.drives
strDriveTypeImg = drivetype(objDrive.drivetype)
strDriveLetter = objDrive
if objDrive.drivetype = 3 then
if objDrive.isReady then
strDriveName = objDrive.ShareName
intFreeSpace = objDrive.FreeSpace
intTotalSpace = objDrive.TotalSize
else
strDriveName = "연결안됨"
intFreeSpace = 0
intTotalSpace = 0
end if
else
if objDrive.isReady then
strDriveName = objDrive.VolumeName
intFreeSpace = objDrive.FreeSpace
intTotalSpace = objDrive.TotalSize
else
strDriveName = "비어있음"
intFreeSpace = 0
intTotalSpace = 0
end if
end if
response.write "<tr bgcolor=white><td align=center>" & strDriveTypeImg & "</td><td align=center>"
if objDrive.isReady then
response.write "<a href=""?command=folders&folder=" & server.urlencode(strDriveLetter) & """>"
end if
response.write strDriveName & " (" & strDriveLetter & ")"
if objDrive.isReady then
response.write "</a>"
end if
response.write "</td><td>" & CalcByte(intFreeSpace) & " / " & CalcByte(intTotalSpace) & "</td></tr>"
next
response.write "</table>"
set fso = nothing
end sub
sub folderlist
dim fso
dim objFolder
dim objSubFolder
dim objFile
dim strName
dim intSize
dim strSort
dim strEditDate
dim strFolder
strFolder = request("folder")
response.write "<table border=0 cellpadding=5 cellspacing=0 align=center width=95% >"
response.write "<tr><td><img src=""images/move.jpg"" border=0 alt=""잘라내기"" style=""cursor:hand;"" onclick=""javascript:document.explorer.action='?command=movefile';document.explorer.submit();""> <img src=""images/copy.jpg"" border=0 alt=""복사"" style=""cursor:hand;"" onclick=""javascript:document.explorer.action='?command=copyfile';document.explorer.submit();""> <img src=""images/paste.jpg"" border=0 alt=""붙여넣기"""
if request.cookies("webexplorer")("filelist") <> "" then
response.write " style=""cursor:hand;"" onclick=""javascript:document.explorer.action='?command=pastefile&folder=" & server.urlencode(strFolder) & "';document.explorer.submit();"""
end if
response.write "> <img src=""images/del.jpg"" border=0 alt=""삭제"" style=""cursor:hand;"" onclick=""javascript:document.explorer.action='?command=delfile';document.explorer.submit();""> <img src=""images/viewfile.jpg"" border=0 alt=""대기작업보기"""
if request.cookies("webexplorer")("filelist") <> "" then
response.write " style=""cursor:hand;"" onclick=""javascript:document.explorer.action='?command=dumplist';document.explorer.submit();"""
end if
response.write "></td></tr>"
response.write"<tr><td align=center><form action=""?command=upload"" name=frmupload method=post enctype=multipart/form-data><input type=file name=ufile> <input type=hidden name=folder value=""" & strFolder & """><input type=button value=""파일올리기"" onclick=""uploadform()""></form></td></tr>"
response.write "</table>" & vbcrlf
response.write "<script language=""javascript"">" & vbcrlf
response.write "function uploadform()" & vbcrlf
response.write "{" & vbcrlf
response.write "if (document.frmupload.ufile.value == """") " & vbcrlf
response.write " {" & vbcrlf
response.write " alert (""업로드할 파일을 선택해주십시요."");" & vbcrlf
response.write " return false;" & vbcrlf
response.write " }" & vbcrlf
response.write "document.frmupload.submit();" & vbcrlf
response.write "}" & vbcrlf
response.write "</script>" & vbcrlf
response.write "<form name=explorer method=post>"
response.write "<table border=0 cellpadding=5 cellspacing=1 bgcolor=black align=center width=95% >"
response.write "<tr bgcolor=#eeeeee align=center><td> </td><td> </td><td>이름</td><td>크기</td><td>종류</td><td>수정된 날짜</td></tr>"
set fso = server.createobject("scripting.filesystemobject")
set objFolder = fso.getfolder( strFolder & "\")
if objFolder.IsRootFolder then
response.write "<tr bgcolor=white><td> </td><td align=center><img src=""images/filefolder.jpg""></td><td><a href=""?command=drives"">..</a></td><td> </td><td> </td><td> </td></tr>"
else
response.write "<tr bgcolor=white><td> </td><td align=center><img src=""images/filefolder.jpg""></td><td><a href=""?command=folders&folder=" & server.urlencode(objFolder.ParentFolder) & """>..</a></td><td> </td><td> </td><td> </td></tr>"
end if
for each objSubFolder in objFolder.subfolders
strName = objSubFolder.Name
strSort = objSubFolder.Type
strEditDate = objSubFolder.DateLastModified
response.write "<tr bgcolor=white><td><input type=checkbox name=""" & objSubFolder & """></td><td align=center><img src=""images/filefolder.jpg""></td><td><a href=""?command=folders&folder=" & server.urlencode(objSubFolder) & """>" & strName & "</a></td><td> </td><td>" & xLeft(strSort,5) & "</td><td>" & mid(strEditDate,1,10) & "</td></tr>"
next
set objSubFolder = nothing
for each objFile in objFolder.files
strName = objFile.Name
intSize = objFile.Size
strSort = objFile.Type
strEditDate = objFile.DateLastModified
response.write "<tr bgcolor=white><td><input type=checkbox name=""" & objFile & """></td><td align=center><a href=""?command=downfile&file=" & server.urlencode(objFile) & """><img src=""images/unknownfiletype.jpg"" border=0></a></td><td><a href=""?command=viewfile&file=" & server.urlencode(objFile) & """>" & strName & "</a></td><td align=right>" & CalcByte(intSize) & "</td><td>" & xLeft(strSort,5) & "</td><td>" & mid(strEditDate,1,10) & "</td></tr>"
next
set objFile = nothing
set objFolder = nothing
set fso = nothing
response.write "</table>"
response.write "</form>"
end sub
Sub downFile()
Dim DownFileName
Dim xDownFileName
Dim fso
Dim file
DownFileName = Request("file")
If Not FileExists(DownFileName) Then
Err.Raise 3, "한머리의 조언", "해당 파일이 존재하지 않습니다."
Exit Sub
End If
Response.Clear
Response.Buffer = true
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private"
Response.CacheControl = "no-cache"
xDownFileName = Mid(DownFileName, InStrRev(DownFileName, "\") + 1, Len(DownFileName) - InStrRev(DownFileName, "\"))
Response.clear
Response.AddHeader "Content-Disposition", " inline; filename=" & xDownFileName & ";"
Response.ContentType = "application/unknown"
set fso = server.CreateObject("SiteGalaxyUpload.FileSystemObject")
set file = fso.OpenBinaryFile(DownFileName, 1, false)
Response.BinaryWrite file.ReadAll
Response.End
set file = nothing
set fso = nothing
End Sub
Sub viewfile()
dim fso
set fso = server.createobject("scripting.filesystemobject")
if fso.getfile(request("file")).size > 1048576 then
Err.Raise 3, "한머리의 조언", "1M이상의 파일을 열 수 없습니다."
else
response.write "<form action=""?command=editfile&file=" & server.urlencode(request("file")) & """ method=post>"
response.write "<textarea name=editfile cols=65 rows=20>"
response.write fso.opentextfile(request("file")).readall
response.write "</textarea>"
response.write "<input type=submit value=""수정하기""> <input type=reset>"
response.write "</form>"
end if
set fso = nothing
End Sub
Sub editFile()
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
fso.opentextfile(request("file"),2).write request("editfile")
Set fso = Nothing
response.redirect "?command=folders&folder=" & server.urlencode(mid(request("file"),1,instrrev(request("file"),"\")-1))
End Sub
Sub delFile()
Dim key
Dim fso
Set fso = server.createobject("scripting.filesystemobject")
if request.form.count=0 then
call goback("폴더나 파일을 선택해주십시요")
else
for each key in request.form
if fso.FolderExists(key) then
fso.DeleteFolder(key)
else
fso.DeleteFile(key)
end if
next
Set fso = Nothing
call goback("요청하신 폴더및 파일이 삭제되었습니다.")
end if
End Sub
Sub upload()
dim uploadform
dim fso
dim fn
Set uploadform = Server.CreateObject("SiteGalaxyUpload.Form")
if uploadform.ContentDisposition <> "form-data" then
err.raise 3,"한머리의 조언", "잘못된 파일 전송 포멧입니다. 관리자에게 연락해주세요"
Exit Sub
end if
if uploadform.Item("ufile").Size > (1048576 * 5) then
Err.Raise 3,"한머리의 조언", "5M이상의 파일을 업로드 할 수 없습니다."
Exit Sub
end if
set fso = server.CreateObject("Scripting.FileSystemObject")
fn = uploadform.item("folder") & "\" & fso.GetFileName(uploadform("ufile").FilePath)
set fso = Nothing
uploadform("ufile").SaveAs(fn)
Set uploadform = Nothing
call goback("파일이 성공적으로 업로드되었습니다.")
End Sub
Sub copyFile()
dim Key
if request.form.count = 0 then
call goback("폴더나 파일을 선택해주십시요.")
else
Response.Cookies("webexplorer")("cmd")="copy"
Response.Cookies("webexplorer")("filelist")=""
For Each Key In request.form
Response.Cookies("webexplorer")("filelist")=Request.Cookies("webexplorer")("filelist") & Key & "/"
Next
call goback("")
end if
End Sub
Sub moveFile()
dim Key
if request.form.count = 0 then
call goback("폴더나 파일을 선택해주십시요.")
else
Response.Cookies("webexplorer")("cmd")="move"
Response.Cookies("webexplorer")("filelist")=""
For Each Key In request.form
Response.Cookies("webexplorer")("filelist")=Request.Cookies("webexplorer")("filelist") & Key & "/"
Next
call goback("")
end if
End Sub
Sub pasteFile()
dim fso
dim strFileList
dim i
if Request.Cookies("webexplorer")("cmd")="move" then
strFileList = split(Request.Cookies("webexplorer")("filelist"),"/")
Set fso = server.createobject("scripting.filesystemobject")
For i = 0 to Ubound(strFileList)-1
if fso.FolderExists(strFileList(i)) then
fso.MoveFolder strFileList(i), request.querystring("folder") & "\"
else
fso.MoveFile strFileList(i), request.querystring("folder") & "\"
end if
Next
set fso = Nothing
response.cookies("webexplorer")("filelist")=""
call goback("폴더 또는 파일 이동을 완료하였습니다.")
else
strFileList = split(Request.Cookies("webexplorer")("filelist"),"/")
Set fso = server.createobject("scripting.filesystemobject")
For i = 0 to Ubound(strFileList)-1
if fso.FolderExists(strFileList(i)) then
fso.CopyFolder strFileList(i), request.querystring("folder") & "\"
else
fso.CopyFile strFileList(i), request.querystring("folder") & "\"
end if
Next
set fso = Nothing
call goback("폴더 또는 파일 복사를 완료하였습니다.")
end if
End Sub
Sub dumpList()
dim strFileList
dim i
Response.write "대기 작업 : " & Request.Cookies("webexplorer")("cmd") & "<br>"
strFileList = split(Request.Cookies("webexplorer")("filelist"),"/")
For i = 0 to Ubound(strFileList)
response.write strFileList(i) & "<br>"
Next
End Sub
%>
'asp' 카테고리의 다른 글
get new non repeated file name on a specific folder (0) | 2010.08.24 |
---|---|
dbhelper class (0) | 2010.08.24 |
read/write configuration class (xml version) (0) | 2010.08.24 |
Encryption Utils Class (0) | 2010.08.24 |
엑셀(CSV) 파일 DB에 입력하기 (2) | 2010.07.09 |