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 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)