dongzhanyan3667 2012-10-03 19:26
浏览 5
已采纳

获取主文件夹

To this day i'm using that piece of code to locate public_html to count the folders to go back in order to import files:

$config_path = array_reverse(explode( DIRECTORY_SEPARATOR , getcwd()));
$co = 0;
foreach($config_path as $val){
    if($val == "public_html")
        break;
    $co += 1;
}
$config_path = '';

if($co != 0){
    for($i = 0 ; $i < $co ; $i++){
        $config_path .= '../';
    }
}

and then i'm using it like that:

require_once ($config_path.'core/db-class.php');

That piece of code serve me pretty good , though I feel like its limiting me because when I use WAMP I need to have public_html folder and such

I'm looking for a php function something like - getMainRoot()

So I can do something like

require_once (getMainRoot().'core/db-class.php');
  • 写回答

2条回答 默认 最新

  • dsvd407787736 2012-10-03 19:27
    关注

    Use the $_SERVER['DOCUMENT_ROOT'] php variable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据