asp

asp 이미지 업로드 및 썸네일 만들기..

ducks228 2010. 12. 20. 11:51


 <% 


 Dim Func
 Dim upload
 Dim method
 Dim pos
 Dim attached_file
 Dim upd

 Dim filepath
 Dim filenameonly
 Dim fileext
 Dim UploadedPath

 Dim filesize
 Dim filename
 Dim file
 Dim ext
 Dim fso
 Dim fileNameTemp
 Dim bExist
 Dim countfilename
 Dim cafeSeq
 Dim dirPath 
 Dim array_filename
 Dim i
 Dim array_lastnum

 'Set Func = New ASPFunc

 Set upload = server.CreateObject("DEXT.FileUpload")


  upload.DefaultPath=Public_Upload_Root
 
  method = upload("method")
  pos = upload("imgPosition")
  attached_file = upload("attachfile")

 'response.write "attached_file==   "&attached_file
  cafeSeq = upload("cafeSeq")
 

  If method = "reg" Then
   If upload("attachfile").FileName <> "" Then
   

 'dextform.DefaultPATH = SAVE_UPLOAD_FILE_PATH  
'response.write "1"
    'upd = Public_CAFE_Upload_Root&"\board\"&cafeSeq
    
    'upload.DefaultPath=upd

    filename = upload.FileName

'file =
'response.write "filename== "&filename&"<br>"

'response.End

 

    filepath = upload.DefaultPath & "\" & filename

    filesize = upload.FileLen
    'filesize = cint(filesize/1024)

    if cint(filesize/1024) > 10240 then
     Response.Write "파일은 10MB 이상의 파일을 올리실 수 없습니다."
     Response.end
    end if

 


    If upload.FileExists(filepath) Then

     ' Get FileName and FileExt
     If InStrRev(filename, ".") <> 0 Then
      filenameonly = Left(filename, InStrRev(filename, ".") - 1)
      fileext = Mid(filename, InStrRev(filename, "."))
     Else
      filenameonly = filename
      fileext = ""
     End If

 

     ' Get Unique FileName
     i = 2
     Do While (1)
      filepath = upload.DefaultPath & "\" & filenameonly & "[" & i & "]" & fileext

      filename= filenameonly & "[" & i & "]" & fileext
      If Not upload.FileExists(filepath) Then Exit Do
      i = i + 1
     Loop
    End If

''''''''''''''''''''''썸네일 생성 시작
 set objImage =server.CreateObject("DEXT.ImageProc")  '썸네일은 실이미지 저장전에만 작동함

'response.write "tempfilepath ===    "&upload.TempFilePath

'response.write "tempfilepath ===    "&attached_file.ImageWidth

   if true = objImage.SetSourceFile(upload.TempFilePath) Then  
    ImageWidth = upload("attachfile").ImageWidth
    ImageHeight = upload("attachfile").ImageHeight

 

'response.write "ImageWidth==    "&ImageWidth&"<br>"
'response.write "ImageHeight==    "&ImageHeight&"<br>"
     fixWidth = 155    '## 썸네일 가로 사이즈
     fixHeight = 102   '## 썸네일 세로 사이즈
   
    If ImageWidth > fixWidth Then
           if ImageWidth > fixWidth or ImageHeight > fixHeight then
               if ImageWidth > ImageHeight then
                   resizeWidth = fixWidth
                   resizeHeight = ImageHeight * fixWidth / ImageWidth
                   if resizeHeight > fixHeight then
                       resizeWidth = fixHeight * ImageWidth / ImageHeight
                       resizeHeight = fixHeight
                   end if
               else
                   resizeHeight = fixHeight
                   resizeWidth = ImageWidth * fixHeight / ImageHeight
                   if resizeWidth > fixWidth then
                       resizeWidth = fixWidth
                       resizeHeight = fixWidth * ImageHeight / ImageWidth
                   end if
               end if
           else
               resizeWidth = obj.width
               resizeHeight = obj.height
           end If
    Else
               resizeWidth = ImageWidth
               resizeHeight = ImageHeight
    End if
    
'response.write "resizeWidth==  "&resizeWidth&"<br>"
'response.write "resizeHeight==   "&resizeHeight&"<br>"


   'strMfile = "s_" & upload("attachfile").FileName
     strMfile = "thumb_" & filename
   'response.write "strMfile==  "&strMfile
   objImage.SaveasThumbnail upload.DefaultPath &"\"& strMfile ,resizeWidth , CInt(resizeHeight), True
'response.write "썸네일.."&"</br>"
   End If
''''''''====== 썸네일 생성 끝

    UploadedPath = upload.SaveAs(filepath)


    array_filename = split(UploadedPath,"\")
    array_lastnum = UBOUND(array_filename)
    filename = array_filename(array_lastnum)

   Set upload =Nothing
   Set objImage =nothing

 

 End if

 

 


'response.write "파일업로드 성공"
%>
<html>

<!-- <Script Language="JavaScript">
 opener.addLink("/upload_cafe/board/<%=cafeSeq%>/<%=filename%>", "<%=filename%>", "<%=pos%>", "1", "", "");
 opener.addList("", "<%=filename %>", "<%=filesize%>");
 opener.addFile("", "<%=filename %>", "<%=filesize%>", "");
 window.close();
</script> -->
</html> 
<%
End if
Set upload=nothing
%>