function set_realpath($path,$check_existance=false)
{
//安全检查以确保路径不是RUL。没有包含远程文件
if(preg_match('#^(http:\/\/|https:\/\/|www\.|ftp|php:\/\/)#i',$path) or filter_var($path,FILTER_VALIDATE_IP)===$path)
{
common()->show_error('你提交的路径必须是本地服务器路径,而不是URL');
}
//解析路径
if(realpath($path) !==false)
{
//realpath()返回规范化的绝对路径名
$path=realpath($path);
}
elseif($check_existance && !is_dir($path) && !is_file($path))
{
common()->show_error('不是有效路径:'.$path);
}
//如果这是一个目录,测添加一个尾随斜杠
return is_dir($path) ? rtrim($path,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR : $path;
}
}