dsbiw2911188 2012-07-25 16:10
浏览 40

替代$ _SERVER ['document_root']作为相对参数

I'm using PHP File Tree to build a directory for a site, and I'm curious what alternatives I have to $_SERVER['DOCUMENT_ROOT'] to make the argument I'm passing through to a function become relative.

The page that calls the function is within the directory I am using the function on, so normally $_SERVER['DOCUMENT_ROOT'] would be perfect except my virtual host is using that directory as the root directory for a domain name.

So, for example, my server/hosting address is http://s389593949.servername.com but the domain www.heresmysite.com resolves to http://s389593949.servername.com/HERESMYSITE/, so the document root when used in the function returns www.heresmysite.com/HERESMYSITE/therealfile.file when it should be www.heresmysite.com/therealfile.file.

Is there something I can put in place of $_SERVER['DOCUMENT_ROOT'] to make it relative? Something like "/" or "../HERESMYSITE/" so when the file name and link are appended they are correct to the relative path? Those do not work.

(Yes, I am aware I can modify the PHP of the function itself, but I'm hoping to leave that untouched as I wish to use it in the future for other applications)

Many thanks, SO.

  • 写回答

1条回答 默认 最新

  • dongmao9217 2012-07-25 16:25
    关注
    $docroot = str_replace('HERESMYSITE/', '', $_SERVER['DOCUMENT_ROOT'])
    
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗