www.gusucode.com > PHP在线生成ico图标小程序源码PHP源码程序 > PHP在线生成ico图标小程序源码/爱生活在线ico图标制作源码/爱生活在线ico图标制作源码/global.php

    <?php

eval('$__file__=__FILE__;');
define('HOME_ROOT',$__file__ ? getdirname($__file__).'/' : './');
$timestamp = time();
$gettime= get_date($timestamp,'Y-m-d H:i:s');
$tdtime = zdStrtoTime(get_date($timestamp,'Y-m-d'));
$getdate= get_date($timestamp,'Y-m-d');
foreach(array('_COOKIE', '_POST', '_GET') as $_request)
{
	foreach($$_request as $_key => $_value)
	{
		$_key{0} != '_' && $$_key = Add_S($_value);
	}
}

if($_SERVER["HTTP_CDN_SRC_IP"]){
	$onlineip = ($_SERVER["HTTP_CDN_SRC_IP"]);
}elseif(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown'))
{
	$onlineip = getenv('HTTP_CLIENT_IP');
}
else if(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown'))
{
	$onlineip = getenv('HTTP_X_FORWARDED_FOR');
}
else if(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown'))
{
	$onlineip = getenv('REMOTE_ADDR');
}
else if(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
	$onlineip = $_SERVER['REMOTE_ADDR'];
}

preg_match("/[\d\.]{7,15}/", $onlineip, $onlineipmatches);
$onlineip = $onlineipmatches[0] ? $onlineipmatches[0] : 'unknown';

if(strpos($onlineip,',') !== false){
	$onlineipdb=explode(',',$onlineip);
	$onlineip=$onlineipdb[0];
}

//DefendCc(1);
unset($onlineipmatches);
ObStart();


function pw_var_export($input,$t = null) {
	switch (gettype($input)) {
		case 'string':
			$input=trim($input);
			return str_replace(array("\\","'"),array("\\\\","\'"),$input);
		case 'array':
			$output = "";
			foreach ($input as $key => $value) {
				$output .= ','.pw_var_export($value,$t);
			}
			$output .= $t."
";
			return $output;
		case 'boolean':
			return $input ? 'true' : 'false';
		case 'NULL':
			return 'NULL';
		case 'integer':
		case 'double':
		case 'float':
			return "'".(string)$input."'";
	}
}

function EchoEot($template,$EXT='htm'){
	return HOME_ROOT."template/$template.$EXT";
}

function get_date($timestamp,$timeformat='')
{
	global $_datefm,$_timedf;
	$db_datefm='Y-m-d H:i:s';
	$db_timedf='8';
	$date_show=$timeformat ? $timeformat : ($_datefm ? $_datefm : $db_datefm);
	if($_timedf)
	{
		$offset = $_timedf=='111' ? 0 : $_timedf;
	}
	else
	{
		$offset = $db_timedf=='111' ? 0 : $db_timedf;
	}
	return gmdate($date_show,$timestamp+$offset*3600);
}
function zdStrtoTime($time){
	global $db_timedf;
	$db_timedf='8';
	return function_exists('date_default_timezone_set') ? strtotime($time) - $db_timedf*3600 : strtotime($time);
}
function Add_S($string, $force = 0)
{
	!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
	if (!MAGIC_QUOTES_GPC || $force)
	{
		if (is_array($string))
		{
			foreach($string as $key => $val)
			{
				$string[$key] = Add_S($val, $force);
			}
		}
		else
		{
			$string = htmlspecialchars($string);
		}
	}
	return $string;
}


function footer(){
	$output = str_replace(array('<!--<!---->','<!---->'),array('',''),ob_get_contents());
	echo ObContents($output);
	unset($output);
	exit;
}
function ObContents($output){

	ob_end_clean();
	if (!headers_sent() && $GLOBALS['db_obstart'] && GetServer('HTTP_ACCEPT_ENCODING') && N_output_zip()!='ob_gzhandler') {
		$encoding = '';
		if (strpos(' '.GetServer('HTTP_ACCEPT_ENCODING'),'gzip') !== false) {
			$encoding = 'gzip';
		} elseif (strpos(' '.GetServer('HTTP_ACCEPT_ENCODING'),'x-gzip') !== false) {
			$encoding = 'x-gzip';
		}
		if ($encoding && function_exists('crc32') && function_exists('gzcompress')) {
			header('Content-Encoding: '.$encoding);
			$outputlen  = strlen($output);
			$outputzip  = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
			$outputzip .= substr(gzcompress($output,$GLOBALS['db_obstart']),0,-4);
			$outputzip .= @pack('V',crc32($output));
			$output = $outputzip.@pack('V',$outputlen);
		} else {
			ObStart();
		}
	} else {
		ObStart();
	}
	return $output;
}
function ObStart(){
	//Copyright (c) 2003-09 PHPWind
	ObGetMode() == 1 ? ob_start('ob_gzhandler') : ob_start();
}
function ObGetMode(){
	//Copyright (c) 2003-09 PHPWind
	static $mode = null;
	if ($mode!==null) {
		return $mode;
	}
	$mode = 0;
	if ($GLOBALS['db_obstart'] && function_exists('ob_gzhandler') && N_output_zip()!='ob_gzhandler' && (!function_exists('ob_get_level') || ob_get_level()<1)) {
		$mode = 1;
	}
	return $mode;
}
function N_flush(){
	//Copyright (c) 2003-09 PHPWind
	if (N_output_zip() == 'ob_gzhandler') {
		return;
	}
	if (php_sapi_name() != 'apache2handler' && php_sapi_name() != 'apache2filter') {
		flush();
	}
	if (function_exists('ob_get_status') && ob_get_status() && function_exists('ob_flush') && !ObGetMode($GLOBALS['db_obstart'])) {
		@ob_flush();
	}
}
function N_output_zip(){
	//Copyright (c) 2003-09 PHPWind
	static $output_handler = null;
	if ($output_handler === null) {
		if (@ini_get('zlib.output_compression')) {
			$output_handler = 'ob_gzhandler';
		} else {
			$output_handler = @ini_get('output_handler');
		}
	}
	return $output_handler;
}
function GetServer($keys){
	//Copyright (c) 2003-09 PHPWind
	foreach ((array)$keys as $key) {
		$server[$key] = NULL;
		if (isset($_SERVER[$key])) {
			$server[$key] = str_replace(array('<','>','"',"'",'%3C','%3E','%22','%27','%3c','%3e'),'',$_SERVER[$key]);
		}
	}
	return is_array($keys) ? $server : $server[$keys];
}
function getdirname($path){
	if(strpos($path,'\\')!==false){
		return substr($path,0,strrpos($path,'\\'));
	}elseif(strpos($path,'/')!==false){
		return substr($path,0,strrpos($path,'/'));
	}else{
		return '/';
	}
}


function ObHeader($URL)
{
	echo "<meta http-equiv='refresh' content='0;url=$URL'>";exit;
}

function makeico($name,$width,$height){
	$date=date("Ymd");
	!$width && $width=16;
	!$height && $height=16;
	$path=dirname (__file__).'/upload/ico/'.$date. '/';
	$filename = $path. '/'.$name;
	//echo $filename;exit;
	$im=@imagecreatefrompng($filename);
	//print_r($im);exit;
	$imginfo = @getimagesize($filename);
	//print_r($imginfo);exit;

	$resize_im = @imagecreatetruecolor($width,$height);
	imagesavealpha($im, true);
	imagealphablending($resize_im, false);//不合并颜色,直接用$im图像颜色替换,包括透明色
	imagesavealpha($resize_im, true);//不要丢了$resize_im图像的透明色,解决生成黑色背景的问题
	imagecopyresampled($resize_im,$im,0,0,0,0,$width,$height,$imginfo[0],$imginfo[1]);

	include_once('inc/phpthumb_ico.class.php');
	$icon = new phpthumb_ico();
	$gd_image_array = array($resize_im);
	$icon_data = $icon->GD2ICOstring($gd_image_array);
	
	$namedb=explode('.',$name);
	$newname=$namedb[0]."_".$width."x".$height. ".ico";
	$filePath=$path.$newname;
	if(file_put_contents($filePath, $icon_data)){
		$output = str_replace($bas_path,'',$filePath);
	}
	header('Content-type: application/ico'); 
	header('Content-Disposition: attachment; filename="'.$newname.'"');
	readfile($filePath);
	unlink($filePath);
}

function delTree($dir) { 
   $files = array_diff(scandir($dir), array('.','..')); 
    foreach ($files as $file) { 
      (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file"); 
    } 
    return rmdir($dir); 
}
?>