class Func{
/////////////////// DB 관련 ///////////////////////
##############################1###############################
# DB 접속 정보를 가지고 있는 화일을 인쿠루드 시키고, 그의 변수 값들을
# 넘기면 된다.
# DB 접속 부분 성공 1반환, 실패 0반환/ 굳이 처리 하지 않아도 상관없다.
#############################################################
function dbConn($HOST, $USER, $PASS, $DBNAME) {
$connect = @mysql_connect($HOST,$USER,$PASS);
if(!$connect) $err = @mysql_error();
$result = @mysql_select_db($DBNAME,$connect);
if(!$result){
$err = @mysql_error();
return 0;
} else return 1;
}
##############################2################################
##
# 반복되는 Row와 Fetch가 귀찮다.
# 종류는 select 시 result, row를 받으면 되고, insert, update,
delete
# 는 exec를 받아서 실행만 하면 땡이다.
###############################################################
#
function sqlrow($query) {
$result = @mysql_query($query);
return @mysql_fetch_array($result);
}
function sqlresult($query) {return @mysql_query($query);}
function sqlfetch($result) {return @mysql_fetch_array
($result);}
function sqlexe($query) {return @mysql_query($query);}
##############################3################################
##
# Count 수와 컬럼 하나의 값을 얻을수있다.
###############################################################
#
function sqlcount($sql) {
$result = @mysql_query($sql);
$row = @mysql_fetch_array($result);
return $row[0];
}
##############################4################################
##
# 게시판에서 현재수보다 1큰 수를 반환하다.
# 보통 mysql auto-increment를 쓰지만..
###############################################################
#
function sqlmaxno($sql) {
$result = @mysql_query($sql);
$row = @mysql_fetch_array($result);
return $row[0]+1;
}
/////////////////// DB 관련 끝///////////////////////
##############################5###############################
# 날짜 구하기이다.. 수시로, 년, 월, 일, 날짜와 시간을 초로 반환한다.
# 구분자는 $str로 하고 year, month, day, all, time, 현재 년-월-일으
로 한다.
# 사용법은 $str를 넘기면서 return 값을 받으면 된다.
# 공동구매나 / 호스팅관리 등 날짜에 관련된 사이트 만들때 유용
#############################################################
function dateSeek($str) {
if($str == "year") return date('Y', mktime());
else if($str == "month") return date('m', mktime());
else if($str == "day") return date('d', mktime());
else if($str == "all") return date('Y-m-d', mktime());
else if($str == "time") return mktime();
else {
$tmpArr=explode("-",$str);
return mktime(0,0,0,$tmpArr[1], $tmpArr[2], $tmpArr[0]);
}
}
##############################6###############################
# 한글을 깨지지 않게 자르는 함수이다.
# 사용법은 함수호출과 더불어 자를 문자열과 길이를 입력하면된다.
# 한글 자르는 함수는 많이 있지만. PHPSCHOOL에서 가장 호응이 좋은걸로
# 택했다.
#############################################################
function hanCut($str, $len) {
if ($len >= strlen($str)) return $str;
$klen = $len - 1;
while(ord($str[$klen]) & 0x80) $klen--;
return substr($str, 0, $len - (($len + $klen + 1) % 2)) ."..";
}
##############################7###############################
# 페이지를 뒤로 강제로 Back 시키고자 할때 사용하면 된다.
# 사용법은 왜 Back을 시키는지 이유를 인자로 넘기면 된다.
##############################################################
// script 오류가 나서.. 몇몇 부분에 "<", ">"를 "{", "}"로 바꿔 났으
니까..
//echo 부분에만 고치시면 됩니다.
function alertBack($msg) {
echo "{script language=javascript}
{/script}";
exit;
}
##############################8###############################
# 페이지를 이동시킬때 쓴다.
# 사용법은 url을 넘기면 끝~
#############################################################
// script 오류가 나서.. 몇몇 부분에 "<", ">"를 "{", "}"로 바꿔 났으
니까..
//echo 부분에만 고치시면 됩니다.
function goUrl($url, $msg) {
if(!empty($msg)) {
echo "
{script}
alert("$msg");
{/script}
";
}
echo "{meta http-equiv='refresh' content="0;URL=$url"}";
exit;
}
############################## 9
##################################
# 파일 업로드할때 호출하면 된다.
# file : form 의 file객체명
# savedir : 저장할 경로 주의 : 디렉토리는 자동생성되지 않고, 권한 역
시 777로 변경
###############################################################
#
function fileUpload($file, $file_name, $savedir) {
if($file != "none") {
$pos = strpos($file_name,".");
$name = substr($file_name,0,$pos);
$ext = substr($file_name,$pos+1);
if(strpos($ext,"php") || !strcmp($ext,"php3") || !strcmp
($ext,"inc") || !strcmp($ext,"pl") || !strcmp($ext,"cgi") ||
!strcmp($ext,"asp") || !strcmp($ext,"") ) {
$this->alertBack("확장자가 $ext 인 화일은 업로드 하실수 없습니다.");
exit;
}
$filename = $savedir.$file_name;
$i = 1;
while(file_exists("$filename")) {
$filename = $savedir.$name."_".$i.".".$ext;
$i++;
}
if(!copy($file,"$filename")) {
$this->alertBack("파일 업로드를 실패했습니다.");
exit;
}
if(!unlink($file)) {
$this->alertBack("임시 파일을 삭제할 수 없습니다.");
exit;
}
$file_name = str_replace($savedir,"",$filename);
return $file_name;
}
}
##############################10###############################
###
# 파일을 삭제할때 호출하면 된다.
# file_name : 삭제할 화일명
# savedir : 저장되어 있는 경로
###############################################################
#
function fileDelete($file_name,$savedir){
$file = $savedir.$file_name;
if(file_exists($file)) unlink($file);
}
##############################11###############################
# 파일을 다운로드 받고자 할때 사용하는 함수이다.
# 사용법은 자기 자신의 페이지를 리플래쉬 하면서
# 함수를 호출하는 방식으로 하면된다.
#############################################################
function saveFile($filename, $savedir) {
$filepath = $savedir.$filename;
if( strstr($_SERVER["HTTP_USER_AGENT"],"MSIE 5.5")){
header("Content-Type: doesn/matter");
header("Content-Disposition: filename=$filename");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
} else{
Header("Content-type: file/unknown");
Header("Content-Disposition: attachment; filename=$filename");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
}
@readfile($filepath);
}
##############################12###############################
###
# 메일 발송하고자 할때 인수를 넘겨주면 된다. (html, text) 발송
# to : 받는사람 메일, from : 발송자 메일, from_name : 발송자명
# subject : 제목, contents : 내용, htmlcheck(y, n) : html발송여부
###############################################################
#
function sendMail($to, $from, $from_name, $subject, $contents,
$htmlcheck) {
$bodytext = $this->htmlText($contents,$htmlcheck);
$additional = "From:$from_name<$from>"."nContent-
Type:text/htmlnReply-To : $from nX-Mailer: PHP/".phpversion();
mail($to,$subject,$bodytext,$additional);
}
############################## 13
##############################
# HTML 적용되는 컨텐츠..
# html사용시에는 y, n으로 구분
###############################################################
#
function htmlText($text, $htmlcheck) {
if($htmlcheck == "n") {
$text = stripslashes($text);
$text = nl2br($text);
}
//html을 사용하는 경우
else {
$text = stripslashes($text);
$text = str_replace("<","<",$text);
$text = str_replace(">",">",$text);
$text = str_replace(""",""",$text);
}
return $text;
}
##############################14###############################
###
# Paging 함수.. 특정값을 넘겨 받아 함수 호출만으로 페이징 처리를 끝낸
다.
# PageNo : 현재 페이지수
# PageSize : 라인수
# totalrows : 총 게시물 수
# whereqry : 전 검색시에 쿼리값을 SQL 조건문
# color : 현재 페이지인 경우 색상
# class : a 로 걸리는 링크에 클래스를 준다.
###############################################################
#
function paging($PageNo, $PageSize, $totalrows, $whereqry,
$color, $class) {
$lastpgno=ceil($totalrows/$PageSize);
if($lastpgno!=0) {
if($PageNo>1) echo " ◀ ";
else echo " ◀ ";
if($PageNo>10) {
$prevPage=floor(($PageNo-1)/10)*10;
echo " ◁ ";
}
else echo " ◁ ";
$i=0;
$startpage=floor(($PageNo-1)/10)*10+1;
while($i<10 && $startpage<=$lastpgno){
if($PageNo<>$startpage) echo " $startpage ";
else echo " $startpage ";
$i++;
$startpage=$startpage+1;
}
$nextPage=floor(($PageNo-1)/10)*10+11;
if($nextPage<$lastpgno) echo " ▷ ";
else echo " ▷ ";
if($PageNo<$lastpgno) echo " ▶ ";
else echo " ▶ ";
}
}
##############################15###############################
###
# 데이타를 가져올 첫 시작 포인트를 반환한다.
###############################################################
#
function getDbStartNo($PageNo, $PageSize) {
return ($PageNo-1)*$PageSize;
}
##############################15###############################
###
# 랜덤 문자열 유일키 발생(상품코드로 사용) / 총 50자인데.. 필요한 만큼
만 자르자.
###############################################################
#
function getCode($len) {
$SID = md5(uniqid(rand()));
$code = substr($SID, 0, $len);
return $code;
}
###############################################################
#
# 세션키 생성 주문번호로 가장 괜찮을거 같아 만들었음
###############################################################
#
function getSession() {
$SID = microtime();
$str = str_replace("-","",date("ymdHis", mktime()));
$session = $str.substr($SID, 4, 3);
return $session;
}
###############################################################
#
# 배열값들 살펴 보기(HTTP_POST_VARS, HTTP_GET_VARS,
HTTP_SERVER_VARS 등
# 이외에 가끔씩. 배열값이 제대로 넘어오는지 확인해야할때가 있다.. 있대
사용..^^
###############################################################
#
function arrayView($Value) {
// 실제로 Array라는 문자열을 뿌려주지면 문자열이 아니여서 다시한번
string 관련함수 하나를 실행해 준다.
$chkArray = ucfirst($Value); //첫문자를 대문자로 변환
if($chkArray == "Array") while(list($key,$val)=each($Value))
echo $key." ==> ".$val."n";
else echo "배열이 아닙니다.";
exit;
}
##############################23###############################
###
# Flash 코드도 꽤 길다.. 그래서. 함수화 해 버렸다.
###############################################################
###
function flashLoad($urlpath, $width, $height) {
echo "
{object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/fla
sh/swflash.cab#version=5,0,0,0" width="$width"
height="$height"}
{param name=movie value="$urlpath"}
{param name=quality value=high}
{embed src="$urlpath" quality=high
pluginspage="http://www.macromedia.com/shockwave/download/index
.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-
shockwave-flash" width="$width" height="$height"}
{/embed}
{/object}
";
}
/////////// 이하는 빌더형 사이트를 변수를 잘 기억하기 힘들어서
^^ //////////
###############################################################
#
# 루트 시스템 절대 경로 얻기
###############################################################
#
function getServerSys() {
return $_SERVER["DOCUMENT_ROOT"];
}
###############################################################
#
# 루트 Url 얻기(메일 발송할때 사용)
###############################################################
#
function getSeverUrl() {
return "http://".$_SERVER["HTTP_HOST"];
}
###############################################################
#
# 현재 시스템 경로 얻기
###############################################################
#
function getSyspath() {
return $_SERVER["SCRIPT_FILENAME"];
}
###############################################################
#
# 현재 URL 경로 얻기
###############################################################
#
function getUrlpath() {
return "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"];
}
###############################################################
#
# 원격지 아이피 얻기
###############################################################
#
function getIp() {
return $_SERVER["REMOTE_ADDR"];
}
} |
|
|