相对路径转绝对路径
/**
* 相对路径转网络绝对路径
* @param string $file
* @return string
*/
function dirtohttpurl($file) {
//判断文件是否存在
if (!file_exists($file)) {
return false;
}
//域名
$nowurl = dirname('http://'.$_server['http_host'].$_server['php_self']); //当前域名
$tempurl = explode('.', $_server['http_host']);
$dirurl = 'http://www.'.$tempurl[1].'.'.$tempurl[2].'/'; //主域名
//文件路径的层次统计
$tempfile = explode('../', $file);
$tempnum = array_count_values($tempfile);
if (array_key_exists('', $tempnum)) {
$filenum = $tempnum[''];
$fileend = end($tempfile);
} else {
$filenum = 0;
$fileend = '/'.substr($tempfile[0], 2);
}
//域名层次统计
$tempweb = explode('/', $nowurl);
$tempweb = array_slice($tempweb, 3);
$webnum = count($tempweb);
//文件对应的域名
if ($filenum > $webnum) {
$nowurl = $dirurl;
}
//返回
return $nowurl.$fileend;
}
//dirtohttpurl('./1.jpg');
ad:真正免费,域名+虚机+企业邮箱=0元