douxia2137
2011-12-14 10:54
浏览 15
已采纳

php需要使用root的功能

I have a site with several sub folders and an include folder in the root:

for example :

www.mysite.com 
www.mysite.com/includes 
www.mysite.com/includes/inc.php

then a sub folder:

www.mysite.com/sub1/
www.mysite.com/sub1/page.php

in page.php I would like to include the inc.php which is in the includes folder. Is that possible, and if so, how can i do that? (tried $_SERVER["DOCUMENT_ROOT"] and didn't work.)

I appreciate the responses, it is quite urgent as I need to move the site to a new server in this format!!!! thanks everyone!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanou8504 2011-12-14 11:09
    已采纳

    I can't think of why document root isn't working but when you do find out, use like this... Have you tried echoing $_SERVER["DOCUMENT_ROOT"] to see what it outputs?

    <?php
    
    define(ROOT, '/home/www/web18/html');
    
    require_once ROOT.'/includes/inc.php';
    
    ?>
    

    Also, run... <?php phpinfo();?>

    There should be root path somewhere...

    enter image description here

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doulei6330 2011-12-14 11:02

    Just use the following syntax in page.php:

    include "../includes/inc.php";

    It will include the inc.php.

    评论
    解决 无用
    打赏 举报
  • doujiao8649 2011-12-14 11:08

    You need to reffer the parent path in your include. Use ../ many times you want to reach your destiny:

    include "../includes/inc.php";

    How your includes dir is on the same level of your sub1 dir, you just have to back one level to see it.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题