파일업로드 클레스
페이지 정보
작성자 MintState 댓글 0건 조회 11,208회 작성일 08-10-29 17:18본문
파일업로드 클레스
4.X 대부터 HTTP_POST_FILES 를 지원합니다.
POST로 넘어온 파일을 컨드롤하는거죠. 버전이 낮은 분은 사용하실 수 없습니다.
금방 만든거라 간편하게 사용할 수 있도록 수정해서 다시 올리도록 하죠.
해당 소스코드를 적당한 이름으로 저장하시고 인크루드 해서 사용하시는건 아시죠? ^^;;
예)
1. 파일의 정보를 확인하려면 다음과 같이 합니다.
$EncFile = new EncFileInfo;
$EncFile -> TempLoad();
2. 파일을 저장하려면 다음과 같이 합니다.
( ErrorExpress는 경고창 띄우고 빽하는 자작함수 -> 제작해서 쓰세요 ^^ )
========================== 소스코드 ===================================
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
?>|
|
댓글목록
등록된 댓글이 없습니다.





파일업로드 클레스