<%@ codepage = 65001%>
<% session.codepage = 65001 %>
<%Response.CharSet = "UTF-8"%>
<%
Dim filename, filenames, path
Dim org_path, trg_path
Dim org_path_file, trg_path_file
Dim fso

filenames = request.queryString( "filenames" )
path = request.queryString( "path" )
path = Replace(path,"/", "\")

org_path = server.mappath("./") & "\Upload\"
trg_path = server.mappath("/") & path

filenames_arr = Split(filenames,"|")

Set fso = server.CreateObject("Scripting.FileSystemObject")

For i = 0 To UBound(filenames_arr)
	org_path_file = org_path & filenames_arr(i)

	If fso.FileExists( org_path_file ) Then

		realfilename = getFileUniqName( trg_path, filenames_arr(i) )				'중복파일명 방지

		If i > 0 Then realfilename_add = realfilename_add & "|"
		realfilename_add = realfilename_add & realfilename

		trg_path_file = trg_path & realfilename
		fso.movefile org_path_file, trg_path_file

	End If

next

Set fso = Nothing

response.write realfilename_add
response.end

Function getFileUniqName(fullpath, filename)
	Dim j
	Dim count, bExist, strname, strext, filename_arr
	Dim fso
	Dim ret_filename

	'파일명과 확장자 분리
	filename_arr	= Split( filename, "." )
	strext			= filename_arr( UBound(filename_arr) )
	strname			= ""
	For j = 0 To UBound(filename_arr)-1
		strname = strname & filename_arr(j)
	Next

	count= 0
	bExist = True
	ret_filename = filename

	Set fso = server.CreateObject("Scripting.FileSystemObject")

	Do While bExist
		If (fso.FileExists(fullpath & ret_filename)) Then
			count = count  + 1
			ret_filename = strname & "(" & count & ")." & strext
		Else
			Exit Do '없으며 빠져나간당..
		End If
	Loop

	getFileUniqName = ret_filename

End function
%>