dsmgcse8876 2015-09-21 12:57
浏览 115
已采纳

PHP获取包含文件的文件路径

I want to include a file which includes a file.. confusing, i'll try to explain a bit more.

I'll show the folder structure first:

  • /main/
  • /main/head.php
  • /main/headertext.txt
  • /main/index.php
  • /main/chat/
  • /main/chat/headertext.txt
  • /main/chat/index.php

I include the file /main/head.php into the file /main/chat/index.php.

Now, in /main/head.php i want to include /main/chat/headertext.txt

In /main/index.php i also include /main/head.php, there i want to include /main/headertext.txt

I don't know if anyone understands me, but i want to include a text file that is in the folder of the current index.php, whatever folder i am in..

Is that possible?

  • 写回答

2条回答 默认 最新

  • duanmian1085 2015-09-21 13:04
    关注

    You can try this:

    define('ROOT_PATH', str_replace(DIRECTORY_SEPARATOR, "/", dirname(dirname(__FILE__)))."/");
    

    And in every file you do your include with this constant. Like this:

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料