1、在Application-->Common-->function.php加入:
function getRoot($file){
$fileUrl=str_replace('\\','/',realpath(dirname($file).'/'))."/";$genIndex=strpos($fileUrl,'/Application/');
if($genIndex>0){
$rootPath=substr($fileUrl,0,$genIndex).'/';//~/home/web/zdm_jsens_com/public_html
return $rootPath;
}
}
2、在Controller下调用:
$rootPath=getRoot(__FILE__);
例如,要查询:根目录-->Uploads-->Images-->a.png
则:$rootPath.'Uploads/Images/a.png';
以下是对应的输出结果展示截图:
A(本地):
B(服务器):