출처 : http://blog.daum.net/thecoolman/3797336
아래 내용을 그대로 가져가서 사용하면 된다.
기본적인 내용은 주석처리 되어 있으니, 사용하는데 별 어려움이 없을 것으로 생각된다.
////////////////////////////////////////////////////////////////////////////////////
<%
'파일업로드 기본 설정
Response.Expires = -10000
Server.ScriptTimeOut = 300
Set theForm = Server.CreateObject("ABCUpload4.XForm")
theForm.Overwrite = True
theForm.MaxUploadSize = 8000000 '8M 업로드 가능
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
theForm.AbsolutePath = True
Dim fileName,fileSize
Function GetUniqueName(strFileName, DirectoryPath)
Dim strName, strExt
'확장자가 없는 경우를 처리
if InstrRev(strFileName, ".") = 0 then
Response.write ""
Response.end
End if
strName = Mid(strFileName, 1, InstrRev(strFileName, ".") - 1)
strExt = Mid(strFileName, InstrRev(strFileName, ".") + 1)
'asp파일 업로드 불가
if strExt = "asa" or strExt = "asp" or strExt = "aspx" or strExt = "inc" or strExt = "bak" or strExt = "php" or strExt = "html" or strExt = "htm" then
Response.write ""
Response.end
End if
Dim bExist : bExist = True
Dim strFileWholePath : strFileWholePath = DirectoryPath & "\" & strName & "." & strExt
Dim countFileName : countFileName = 0
Do While bExist
If (fso.FileExists(strFileWholePath)) Then
countFileName = countFileName + 1
strFileName = strName & "(" & countFileName & ")." & strExt
strFileWholePath = DirectoryPath & "\" & strFileName
Else
bExist = False
End If
Loop
GetUniqueName = strFileWholePath
End Function
Sub Exec_fileUp(newFile,deleteFile,deleteFilesize,DirectoryPath,num)
Set theField = newFile(num+1)
If theField.FileExists Then '만일 파일업을 했으면...
strFileName = theField.SafeFileName '파일 명
strFileSize = theField.Length '파일 사이즈
'파일명을 정한다.
strExt = Mid(strFileName, InstrRev(strFileName, ".") + 1)
strName = Date() & Hour(time) & Minute(time) & Second(time)
strName = Replace(strName,"-","")
strFileName = strName & "." & strExt
if theField.Length > 8000000 then
Response.Write ""
Response.end
Else
if Len(deleteFile) > 0 then '삭제 화일이 있을경우..
delfile = DirectoryPath & "\" & deleteFile
If (fso.FileExists(delfile)) Then
fso.DeleteFile(delfile) '파일을 지운다..
End if
End if
strFileWholePath = GetUniqueName(strFileName, DirectoryPath) '적합한 파일인지 체크한다.
theField.Save strFileWholePath '파일을 저장한다.
End if
fileName = strFileName
fileSize = strFileSize
Else
fileName = deleteFile
fileSize = deleteFilesize
End If
End Sub
'파일 업로드, 업로드 폼이 추가 되면 아래 문장만 추가하면 된다. 물론 파일명은 수정해 줘야 한다.
CALL Exec_fileUp(theForm.item("fileUpload"),"","",DirectoryPath,0)
위 CALL 문장은 파일을 업로드 하는데 사용을 하면 되고,
수정을 할 경우에는.. 아래 문장을 사용하면 된다.
사용할 경우 삭제할 파일명과 사이즈를 먼저 구한 후에 실행을 해야 한다.
<%
'파일 업로드 및 삭제
CALL Exec_fileUp(theForm.item("fileUpload"),DelfileUpLoad,DelfileSize,DirectoryPath,0)
%>
파일을 다운로드 받을 경우, Stream 을 이용해서 다운을 받는다.
<%
'파일 이름
FileName = Request("FileName")
Response.ContentType = "application/unknown" 'ContentType 를 선언합니다.
Response.AddHeader "Content-Disposition","attachment; filename=" & FileName '헤더값이 첨부파일을 선언
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile Server.MapPath("\admin\ad\UpLoad") & "\" & FileName '절대경로
download = objStream.Read
Response.BinaryWrite download '이게 보통 Response.Redirect 로 파일로 연결시켜주는 부분을 대신하여 사용된 것입니다.
Set objstream = nothing
%>
'ASP' 카테고리의 다른 글
asp 노캐쉬 (0) | 2013.10.29 |
---|---|
엑셀전환시 <br>태그 (0) | 2013.10.28 |
폴더검색 fso (0) | 2013.10.24 |
asp 모든폼 갖고오기 (0) | 2013.10.24 |
Dext sumnail 새창으로 메일 보기 (0) | 2013.10.24 |