본문 바로가기

Programming/Web

[asp] SiteGalaxy Upload Function

  Set up = Server.CreateObject("SiteGalaxyUpload.Form")
  Set fs = CreateObject("Scripting.FileSystemObject")
  
  Function UploadFile(obj, folder, prevFile)
   fieldValue = up(Cstr(obj))
   if fieldValue <> "" then
    Dim fn, strFileName, strPath, rootpath, returnValue
    fn = ""
    strFileName = ""
    returnValue = ""
    
    rootpath = Server.MapPath("/")
'   uploadpath = rootpath & "\upload_file\" & folder & "\" & up.Item(Cstr(obj)).MimeType & "\"
    strPath = rootpath & "\upload_file\" & folder & "\"
    
'     if fs.FileExists(strPath & prevFile) then
'      fs.DeleteFile(strPath & prevFile)
'     end if
    
    fn = fs.GetFileName(up(Cstr(obj)).FilePath)
    strFileName = strPath & fn

    if fs.FileExists( strFileName ) then
     countFileName = 0
     Do while fs.FileExists(strFileName)
      strFileHead = ""
      strFileExt = ""

      strExt_arr = Split(fn, ".")
      for j=0 to Ubound(strExt_arr)-1
       strFileHead = strFileHead & strExt_arr(j)
      next
      strFileExt = strExt_arr(Ubound(strExt_arr))

      countFileName = countFileName + 1
      fn = strFileHead & "_" & countFileName & "." & strFileExt
      strFileName = strPath & fn
     Loop
    end if
    up(Cstr(obj)).SaveAs(strFileName)

    if fs.FileExists( strFileName ) then
     returnValue = fn
    end if
    uploadFile = returnValue
   end if
  End Function


=====
필요하신 분은 퍼가시되 환경에 따라 이대로 작동을 안할 수도 있으니 환경에 맞춰서 적절히 수정하시기 바랍니다.