Class 사용법

PHP 2013. 10. 27. 13:14

class MemberProcess
{
  var $SQL = "";
   var $ReturnArr = array("Result"=>"","Msg"=>"");

        function MemberProcess()    //클래스 생성자
        {
            $this->db   =   new CDB;
            $this->db->Connect();
        }


        function CheckId($Uid)     // ID존재여부를 체크한다.
        {
            $this->SQL    =   " select * from TB_manager where user_id = '$Uid' ";
            $this->db->Query($this->SQL);
            $this->total  =   $this->db->RecordCount();
            return $this->total;
        }

        function CheckPwd($Uid,$PassWd)   // 비밀번호가 맞는지 체크한다.
        {
                $this->SQL = " select * from TB_manager where user_id = '$Uid' and user_pwd = '$PassWd' ";
                $this->db->Query($this->SQL);
        //      echo $this->SQL ;
                $this->total = $this->db->RecordCount();
                return $this->total;
        }


        function LoginChk($Uid, $PassWd)  //유효한 사용자인지 로그인전 확인한다.
        {
                if($this->CheckId($Uid) <= 0)
                {
                        $this->ReturnArr[Result] = false;
                        $this->ReturnArr[Msg] = $Uid."는 존재하지 않는 아이디 입니다";
                }
                else
                {
                        if($this->CheckPwd($Uid, $PassWd) <= 0)
                         {
                                $this->ReturnArr[Result] = false;
                                $this->ReturnArr[Msg] = "비밀번호가 일치하지 않습니다.!";
                         }
                        else
                         {
                                $this->ReturnArr[Result] = true;
                                $this->ReturnArr[Msg] = "";
                         }
                }

                return $this->ReturnArr;

        }


        function LogOut($cookie_domain="")   //로그아웃을 처리한다.
        {
          setcookie("web_id","",0,"/",$cookie_domain);
          setcookie("web_name","",0,"/",$cookie_domain);
          setcookie("web_email","",0,"/",$cookie_domain);
          setcookie("web_level","",0,"/",$cookie_domain);
          setcookie("web_company","",0,"/",$cookie_domain);


          $this->ReturnArr[Result] = true;
          $this->ReturnArr[Msg] = "안녕히 가십시오..";

          return $this->ReturnArr;

        }

        function LogIn($Uid,$Pwd,$cookie_domain="")  //로그인을 처리한다.
        {

          $RtnArr = $this->LoginChk($Uid,$Pwd);

           if($RtnArr[Result])
            {
              $row = $this->db->fetcharray();

              SetCookie("web_id",$row[user_id], 0, "/", $cookie_domain);
              SetCookie("web_name",$row[user_name], 0, "/", $cookie_domain);
              SetCookie("web_email",$row[user_email], 0, "/", $cookie_domain);
              SetCookie("web_level",$row[user_level], 0, "/", $cookie_domain);
              SetCookie("web_company",$row[member_of], 0, "/", $cookie_domain);

            }

          return $RtnArr;

 

        }
}

 


/**********************************************************************
  사용 방법
***********************************************************************  
include_once "class/DB.php";  // DB연결 클래스 샘플은 아래 있당
include_once "class/MemberProcess.php"; //로그인 처리 클래스

 

$cMember = new MemberProcess;  //클래스 생성

 

//로그인 처리 LogIn(아이디,비밀번호,쿠키URL)
$Cuser = $cMember->LogIn("hawk5","hawk6","mydomain.com");

 

//로그인 결과 처리

if($Cuser[Result])
{
        echo("
            <script>
                location.href='/';
            </script>
        ");
}
else
{
        echo("<script>alert('$Cuser[Msg]');history.go(-1);</script>");
}

***************************************************************************/
  
?>

 

 

 

[펌] http://blog.naver.com/neohawk5?Redirect=Log&logNo=140131812745

'PHP' 카테고리의 다른 글

클래스 & 객체  (0) 2013.10.27
Class 예문  (0) 2013.10.27
파일업로드 시 파일명 관리  (0) 2013.10.24
파일다운  (0) 2013.10.24
PHP 환경변수  (0) 2013.10.24
Posted by 초보용
,

출처 : 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
Posted by 초보용
,

<?php
//업로드 폴더
$path = './upload/';

//파일이 정상적으로 서버까지 올라온 상태라면
$img_file = $_FILES['img']['tmp_name'];
if ($img_file)
{
#################
### 변수 정의 ###
#################

//그냥 파일명
$img_file_name = $_FILES['img']['name'];

//파일명 추출을 위한 배열 생성
$file_type_check = explode('.',$img_file_name);
//print_r($file_type_check);

//파일 확장자 체크
$file_type = $file_type_check[count($file_type_check)-1];
//echo $file_type;

//확장자를 제외한 파일명 추출
$i = 0;
while($i < count($file_type_check)-1){
$real_filename .= $file_type_check[$i];
$i++;
}
//echo $real_filename;


#######################################################
####### 파일 명에 숫자 붙여서 업로드 하는 형태 ########
#######################################################

//파일 존재 여부 체크
$exist_flag = 0;
if(file_exists($path.$real_filename.'.'.$file_type)){ //파일이 존재한다면
$i = 0;
while($exist_flag != 1){ //존재하지 않을때 까지 루프
if(!file_exists($path.$real_filename.'['.$i.'].'.$file_type)){ // 경로/파일명[$i].확장자 존재한다면
 $exist_flag = 1; // 존재함을 표시하고
 $img_file_name = $real_filename.'['.$i.'].'.$file_type; // 확인된 파일명으로 업로드 파일명 설정
}
$i++;
}

}
//파일 업로드
if(!@copy($img_file, $path.$img_file_name)) { echo("error"); }


#######################################################
####### 파일명을 업로드 시간으로 변경하는 형태 ########
#######################################################

//시분초.확장자
$img_file_name = date("YmdHis").'.'.$file_type;
if(!@copy($img_file, $path.$img_file_name)) { echo("error"); }

###################################################
####### 파일명에 업로드 시간을 붙이는 형태 ########
###################################################

//파일명_시분초.확장자
$img_file_name = $real_filename."_".date("YmdHis").'.'.$file_type;
if(!@copy($img_file, $path.$img_file_name)) { echo("error"); }

}


// 이건 간단한 업로드 형태이고,

// 최근 포털등의 업로드 형태는 가만... 보면
// 서버에 업로드 되었을때는 파일명 자체를 암호화(?) 등의 패턴 형태로 업로드 시키고,
// 업로드한 파일명을 따로 관리한다

// 즉 db 에 파일명 필드가
// 유저가 업로드한 파일명 || 실제 서버에 업로드 되어 있는 파일명
// 으로 구분해서 관리한다는 뜻이다.

// 위에 제시한 방식은 블로그 방문자의 요청에 의해
// 유저가 업로드 한 파일명을 컨트롤 하는 형태이다.

// 유저가 업로드한 파일명 || 실제 서버에 업로드 되어 있는 파일명 으로 관리하겠다고 하면
// 업로드 되는 파일명 자체를 md5 해서 쓰거나 str_replace(urlencode(파일명),'%','') 이런식으로 쓰는것도 나쁘지 아니한것 같다.

'PHP' 카테고리의 다른 글

Class 예문  (0) 2013.10.27
Class 사용법  (0) 2013.10.27
파일다운  (0) 2013.10.24
PHP 환경변수  (0) 2013.10.24
쿠키  (0) 2013.10.24
Posted by 초보용
,