<% Response.CharSet = "euc-kr" Response.AddHeader "Pragma","no-cache" Response.Expires = -1 Dim attachClientIp attachClientIp = Replace(Replace(Trim(Request.ServerVariables("REMOTE_ADDR")), "10.10.20.", "10.10.13."), "10.10.17.", "10.10.13.") If attachClientIp <> "10.10.13.47" And _ attachClientIp <> "10.10.13.105" And _ attachClientIp <> "10.10.13.48" And _ attachClientIp <> "10.10.13.6" And _ attachClientIp <> "10.10.13.29" Then Response.Write "{""result"":""denied""}" Response.End End If Dim uploadform, fso, krc_no, folderPath, i, foundSlot, targetPath, fileName, ext Dim allowedExt, folderObj, oneFile, us, dt, idxPart Dim usedSlot(20) ' PDFs are rasterized into jpg on the client (pdf.js) before upload, same as the ' registration page, so the server only ever needs to save the file as-is. allowedExt = "|jpg|jpeg|png|gif|zip|pdf|hwp|doc|docx|xls|xlsx|ppt|pptx|" Set uploadform = Server.CreateObject("DEXT.FileUpload") uploadform.Codepage = 949 krc_no = uploadform("krc_no") If krc_no = "" Or InStr(krc_no, "..") > 0 Or InStr(krc_no, "/") > 0 Or InStr(krc_no, "\") > 0 Then Response.Write "{""result"":""fail""}" Response.End End If fileName = uploadform("attach_file")(1).FileName If fileName = "" Then Response.Write "{""result"":""fail""}" Response.End End If ext = LCase(Mid(fileName, InStrRev(fileName, ".") + 1)) If InStr(allowedExt, "|" & ext & "|") = 0 Then Response.Write "{""result"":""badtype""}" Response.End End If Set fso = Server.CreateObject("Scripting.FileSystemObject") folderPath = Server.Mappath("/") & "/Upload/DOC_ATTACH/" & krc_no If fso.FolderExists(folderPath) = False Then fso.CreateFolder folderPath End If ' find used index slots regardless of extension Set folderObj = fso.GetFolder(folderPath) For Each oneFile In folderObj.Files us = InStrRev(oneFile.Name, "_") dt = InStrRev(oneFile.Name, ".") If us > 0 And dt > us Then idxPart = Mid(oneFile.Name, us + 1, dt - us - 1) If IsNumeric(idxPart) Then If CInt(idxPart) >= 1 And CInt(idxPart) <= 20 Then usedSlot(CInt(idxPart)) = 1 End If End If End If Next foundSlot = 0 For i = 1 To 20 If usedSlot(i) <> 1 Then foundSlot = i Exit For End If Next If foundSlot = 0 Then Response.Write "{""result"":""full""}" Response.End End If targetPath = folderPath & "/" & krc_no & "_" & CStr(foundSlot) & "." & ext uploadform("attach_file")(1).saveAs(targetPath) Response.Write "{""result"":""ok""}" Set fso = Nothing Set uploadform = Nothing %>