<?php
	// 获取订单
	function DD(){
		return date('YmdHis').rand(100000, 999999);
	}
	// 获取字符
	function GET($arg){
		return htmlentities(trim($_REQUEST[$arg]),ENT_QUOTES,"UTF-8");
	}
	// 获取字符、仅限于ABCabc123_.@
	function ABC($arg,$min=0,$max=0){
		$abc = trim($_REQUEST[$arg]);
		if(@ereg('^([0-9]|[a-z]|[A-Z]|_|\.|@)*$',$abc)){
			if($min && strlen($abc) < $min) return false;
			else if($max && strlen($abc) > $max) return false;
			else if($min && $max && (strlen($abc) < $min || strlen($abc) > $max)) return false;
			else return $abc;
		}
		else return false;
	}
	// 获取整型
	function INT($arg){
		$int = trim($_REQUEST[$arg]);
		if(@ereg('^[-+]?(0|[1-9][0-9]*)$',$int)) return $int;
		else return 0;
	}
	// 验证EMAIL
	function EMAIL($str){
		return filter_var($str, FILTER_VALIDATE_EMAIL);
	}
	
	// 获取IP
	function IP(){
		$clientIp = "";
        if (isset ($_SERVER)) {
            if (isset ($_SERVER["HTTP_X_FORWARDED_FOR"])) {
                $clientIp = $_SERVER["HTTP_X_FORWARDED_FOR"];
            } elseif (isset ($_SERVER["HTTP_CLIENT_IP"])) {
                $clientIp = $_SERVER["HTTP_CLIENT_IP"];
            } else {
                $clientIp = $_SERVER["REMOTE_ADDR"];
            }
        }
        return $clientIp;
	}
	
	// 上传图片、成功则返回其类型、如.jpg   .gif
	function IMAGE($arg,$folder){
		// 上传配置
		$config = array(
			"fileType" => array(".gif",".png",".jpg",".jpeg",".bmp"),   //文件允许格式
			"fileSize" => 2048                                         //文件大小限制，单位KB
		);
		// 文件上传结果,初始默认成功，可选参数{"SUCCESS","ERROR","SIZE","TYPE"}
		$rel = "SUCCESS";
		//格式验证
		$current_type = strtolower(strrchr($_FILES[$arg]["name"], "."));
		if(!in_array($current_type, $config["fileType"])){$rel = "TYPE";}
		//大小验证
		$file_size = $config["fileSize"] * 1024;
		if($_FILES[$arg]["size"] > $file_size){$rel = "SIZE";}
		//保存图片
		if($rel == "SUCCESS"){
			$result = @move_uploaded_file($_FILES[$arg]["tmp_name"],$folder.$current_type);
			if($result === false){
				$rel = "UPLOAD";
			}else{
				$rel = $current_type;
			}
		}
		// 返回结果
		return $rel;
	}
?>