//获取当年http协议
function http()
{
return (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
}
function get_domain(){
//协议
$protocol = $this->http();
/* 域名或IP地址 */
if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
{
$host = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
elseif (isset($_SERVER['HTTP_HOST']))
{
$host = $_SERVER['HTTP_HOST'];
}
else
{
/* 端口 */
if (isset($_SERVER['SERVER_PORT']))
{
$port = ':' . $_SERVER['SERVER_PORT'];
if ((':80' == $port && 'http://' == $protocol) || (':443' == $port && 'https://' == $protocol))
{
$port = '';
}
}
else
{
$port = '';
}
if (isset($_SERVER['SERVER_NAME']))
{
$host = $_SERVER['SERVER_NAME'] . $port;
}
elseif (isset($_SERVER['SERVER_ADDR']))
{
$host = $_SERVER['SERVER_ADDR'] . $port;
}
}
return $protocol . $host;
}
//获取当前url地址
function url()
{
$curr = strpos(PHP_SELF, ADMIN_PATH . '/') !== false ?
preg_replace('/(.*)(' . ADMIN_PATH . ')(\/?)(.)*/i', '\1', dirname(PHP_SELF)) :
dirname(PHP_SELF);
$root = str_replace('\\', '/', $curr);
if (substr($root, -1) != '/')
{
$root .= '/';
}
return $this->get_domain() . $root;
}
/**
* 获得数据目录的路径
*
* @param int $sid
*
* @return string 路径
*/
function data_dir($sid = 0)
{
if (empty($sid))
{
$s = 'data';
}
else
{
$s = 'user_files/';
$s .= ceil($sid / 3000) . '/';
$s .= $sid % 3000;
}
return $s;
}
/**
* 获得图片的目录路径
*
* @param int $sid
*
* @return string 路径
*/
function image_dir($sid = 0)
{
if (empty($sid))
{
$s = 'images';
}
else
{
$s = 'user_files/';
$s .= ceil($sid / 3000) . '/';
$s .= ($sid % 3000) . '/';
$s .= 'images';
}
return $s;
}
}