Thinkphp 控制器php 获取根目录

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(服务器):



猜你喜欢

转载自blog.csdn.net/qq_36376116/article/details/79180400