|
PHP复制代码
<?php
if ( ! defined('E_STRICT'))
{
define('E_STRICT', 2048);
}
//检查文件是否可写
function is_really_writable ($file)
{
if (DIRECTORY_SEPARATOR == '/' AND @ini_get("safe_mode") == FALSE)
{
return is_writable($file);
}
if (is_dir($file))
{
$file = rtrim($file, '/').'/'.md5(rand(1,100));
if (($fp = fopen($file, FOPEN_WRITE_CREATE )) === FALSE)
{
return FALSE;
}
fclose($fp);
@chmod($file, DIR_WRITE_MODE );
@unlink($file);
return TRUE;
}
elseif (($fp = @fopen($file, FOPEN_WRITE_CREATE )) === FALSE)
{
return FALSE;
}
fclose($fp);
return TRUE;
}
//载入配置文件
function &get_config ()
{
static $main_conf;
if ( ! isset($main_conf))
{
if ( ! file_exists(APPPATH .'config/config'.EXT ))
{
exit('配置文件不存在.');
}
require(APPPATH .'config/config'.EXT );
if ( ! isset($config) OR ! is_array($config))
{
exit('你的配置文件格式不正确.');
}
$main_conf[0] =& $config;
}
return $main_conf[0];
}
//获取配置项
function config_item ($item)
{
static $config_item = array();
if ( ! isset($config_item[$item]))
{
$config =& get_config ();
if ( ! isset($config[$item]))
{
return FALSE;
}
$config_item[$item] = $config[$item];
}
return $config_item[$item];
}
//载入类
function &load_class ($class, $instantiate = TRUE)
{
static $objects = array();
if (isset($objects[$class]))
{
return $objects[$class];
}
require(BASEPATH .'libraries/'.$class.EXT );
if ($instantiate == FALSE)
{
$objects[$class] = TRUE;
return $objects[$class];
}
$objects[$class] =& new $class();
return $objects[$class];
}
//写入日志
function log_message ($level = 'error', $message, $php_error = FALSE)
{
static $LOG;
$config =& get_config ();
if ($config['log_threshold'] == 0)
{
return;
}
$LOG =& load_class ('Log');
$LOG->write_log($level, $message, $php_error);
}
//自定义错误函数
function _exception_handler ($severity, $message, $filepath, $line)
{
if ($severity == E_STRICT)
{
return;
}
$error =& load_class ('Exceptions');
if (($severity & error_reporting()) == $severity)
{
$error->show_php_error($severity, $message, $filepath, $line);
}
$config =& get_config ();
if ($config['log_threshold'] == 0)
{
return;
}
$error->log_exception($severity, $message, $filepath, $line);
}
//显示错误
function show_error ($message)
{
$error =& load_class ('Exceptions');
echo $error->show_error('系统出现错误:', $message);
exit;
}
//无法显示网页
function show_404 ($page = '')
{
$error =& load_class ('Exceptions');
$error->show_404($page);
exit;
}
?>
复制代码 |
|