duansha8115 2011-12-05 22:03
浏览 108
已采纳

DOCUMENT_ROOT不完整,缺少域文件夹

I have searched many threads so far but cant seem to find a solution. Inside one of my php scripts I am trying to get a server document root but the value I get is not complete, its simply missing the domain folder. I believe it is due to sharing hosting or smth else.

Here is the current way I am using:

$root = realpath($_SERVER["DOCUMENT_ROOT"]);

and the path I get is like:

/home/content/01/0151247/html

although I know it should be like:

/home/content/01/0151247/html/mydomain

I know as I compared it with SCRIPT_NAME and I see the mydomain there in the path.

Hope someone could direct me.

Thank you and sorry for probably asking another thousand time same question over community, I really tried things around from here, nothing helps me so far.

UPDATE

unfortunately I cant not simply use my index file with DIR as it is a wordpress setup and I am working on a separate folder where I am including some wordpress functionality but for that I need a document_root. If that would help.

UPDATE

apparantly the following way resolved my case, maybe it will help someone one day:

realpath($_SERVER["SUBDOMAIN_DOCUMENT_ROOT"]);

basically because of the server setup and domain configured as a subdomain.

Thanks to all who participated.

  • 写回答

3条回答 默认 最新

  • dtjo51649 2011-12-05 22:08
    关注

    Prior to PHP 5.3 you can put a file in the directory whose path you want and define a constant:

    define('ROOT_DIR', dirname( __FILE__ ));
    

    After 5.3 you can just do:

    define('ROOT_DIR', __DIR__);
    

    The idea being that this would be in config.php of some sort that is included every time the application runs.

    Magic Constants Docs

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

报告相同问题?

悬赏问题

  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM