YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > PHP
검색
멤버이름    오토
비밀번호 
 

파일업로드 클레스

페이지 정보

작성자 MintState 댓글 0건 조회 10,506회 작성일 08-10-29 17:18

본문

파일업로드 클레스
 
4.X 대부터 HTTP_POST_FILES 를 지원합니다.
POST로 넘어온 파일을 컨드롤하는거죠. 버전이 낮은 분은 사용하실 수 없습니다.
금방 만든거라 간편하게 사용할 수 있도록 수정해서 다시 올리도록 하죠.
해당 소스코드를 적당한 이름으로 저장하시고 인크루드 해서 사용하시는건 아시죠? ^^;;

예)
1. 파일의 정보를 확인하려면 다음과 같이 합니다.

$EncFile = new EncFileInfo;
$EncFile -> TempLoad();

2. 파일을 저장하려면 다음과 같이 합니다.
( ErrorExpress는 경고창 띄우고 빽하는 자작함수 -> 제작해서 쓰세요 ^^ )

$EncFile = new EncFileInfo; 
$EncFile -> ReadinPost(); 
$out = $EncFile -> ImageFileLimit(); 
if( $out ) 
{ 
       ErrorExpress($out[errMsg]); 
       exit; 
} 
$EncFile -> ResetFileDir("/home/test/public_html/board/images");//저장할 디렉토리 재설정 
$out = $EncFile -> FileWriteExec(); 
if( $out ) 
{ 
       ErrorExpress($out[errMsg]); 
       exit; 
}


========================== 소스코드 ===================================
<?php 
/*************************************************************** 
//제작자: 얼룩푸우(budget74@nate.com) 
//용  도: 파일 업로드 
//제작일: 2003년 04월 30일 
****************************************************************/ 

class EncFileInfo 
{ 
       var $_post; 
       var $_count; 
       var $_error; 
       var $_limit_size = '2000'; 
       var $_exception = 'image'; 
       var $_wirte_dir = 'image'; 

       ## POST 로 넘어온 파일을 체크할 때 쓴다 
       function TempLoad() 
       { 
              global $HTTP_POST_FILES; 
              while( list( $k, $v )=each( $HTTP_POST_FILES ) ) 
              { 
                     echo $k." = ".$v."<br>"; 
                     while( list( $x, $y ) = each( $v) ) 
                     { 
                            echo $x." = ".$y."<br>"; 
                     } 
              } 
       } 
       ## POST 값를 클레스의 객체로 REWRITE 
       function ReadinPost() 
       { 
              global $HTTP_POST_FILES; 

              for( $i=0; list( $k, $v )=each( $HTTP_POST_FILES ); $i++ ) 
              { 
                     $this->_post["vars"][$i] = $k; 
                     $this->_post[$k] = $v; 
                     while( list( $x, $y ) = each( $v ) ) 
                     { 
                            $this->_post[$x][$i] = $y; 
                     } 
              } 
              $this->_count = $i; 
       } 
       ## 파일 용량 제한을 재설정 
       function ResetFileSize( $size ) 
       { 
              $this->_limit_size=$size; 
       } 
       ## 파일 MIME/TYPE 제한을 재설정 
       function ResetFileExec( $exec ) 
       { 
              $this->_exception=$exec; 
       } 
       ## 파일 쓰는 디렉토리 설정 
       function ResetFileDir( $dir ) 
       { 
              $this->_wirte_dir=$dir; 
       } 
       ## 업로드 파일의 MIME/TYPE 제한 
       #  이미지만 가능 
       function ImageFileLimit() 
       { 
              for( $i=0; $i < $this->_count; $i++ ) 
              { 
                     if( strcmp(current(explode('/', $this->_post["type"][$i])),$this->_exception) ) 
                     { 
                            $this->_error["Result"] = 401; 
                            $this->_error["errMsg"] = "죄송합니다. 업로드 파일은 GIF,JPG 같은 이미지 파일만 가능합니다."; 
                            return $this->_error; 
                            exit; 
                     } 
              } 
              return 0; 
       } 
       #  설정을 빼고 모두 가능 
       function FileLimitNegative() 
       { 
              for( $i=0; $i < $this->_count; $i++ ) 
              { 
                     if( !strcmp(current(explode('/', $this->_post["type"][$i])),$this->_exception) ) 
                     { 
                            $this->_error["Result"] = 402; 
                            $this->_error["errMsg"] = "죄송합니다. 해당 파일은 업로드가 제한되어 있습니다."; 
                            return $this->_error; 
                            exit; 
                     } 
              } 
              return 0; 
       } 
       ## 업로드 파일의 용량의 제한 
       function ByteFileLimit() 
       { 
              for( $i=0; $i < $this->_count; $i++ ) 
              { 
                     if( $this->_post["type"][$i] > $limit ) 
                     { 
                            $this->_error["Result"] = 403; 
                            $this->_error["errMsg"] = "죄송합니다. 업로드 파일은 ".$this->_limit_size."Byte로 제한되어 있습니다."; 
                            return $this->_error; 
                            exit; 
                     } 
              } 
              return 0; 
       } 
       ## 파일 쓰기 
       function FileWriteExec() 
       { 
              if( !is_dir($this->_wirte_dir) ) 
              { 
                     $this->_error["Result"] = 404; 
                     $this->_error["errMsg"] = "죄송합니다. 파일을 저장할 디렉토리가 존재하지 않습니다."; 
                     return $this->_error; 
                     exit; 
              } 
              for( $i=0; $i < $this->_count; $i++ ) 
              { 
                     if( $this->_post["vars"][$i] ) 
                     { 
                            if( !copy($this->_post[tmp_name][$i],$this->_wirte_dir."/".$this->_post["name"][$i]) ) 
                            { 
                                   $this->_error["Result"] = 405; 
                                   $this->_error["errMsg"] = "죄송합니다. 파일을 지정한 디렉토리에 복사하는데 실패하였습니다."; 
                                   return $this->_error; 
                                   exit; 
                            } 
                            if( !unlink($this->_post[tmp_name][$i]) ) 
                            { 
                                   $this->_error["Result"] = 406; 
                                   $this->_error["errMsg"] = "죄송합니다. 임시파일을 삭제하는데 실패하였습니다."; 
                                   return $this->_error; 
                                   exit; 
                            } 
                     } 
              } 
              return 0; 
       } 


}//End Class 
?>

댓글목록

등록된 댓글이 없습니다.

Total 165건 6 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
40 MintState 12473 10-31
39 MintState 13227 10-31
38 MintState 11435 10-31
37 MintState 12919 10-31
36 MintState 13638 10-31
35 MintState 11435 10-31
34 MintState 11069 10-31
33 MintState 17854 10-31
32 MintState 14496 10-31
31 MintState 11722 10-31
30 MintState 13528 10-29
29 MintState 17831 10-29
28 MintState 12207 10-29
27 MintState 10419 10-29
26 MintState 16333 10-29
25 MintState 13339 10-29
24 MintState 14736 10-29
23 MintState 14722 10-29
22 MintState 14817 10-29
21 MintState 12183 10-29
20 MintState 11009 10-29
19 MintState 11462 10-29
18 MintState 12444 10-29
열람중 MintState 10507 10-29
16 MintState 9727 10-29
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™