Why does this PHP relative include fail?

前端 未结 2 692
遥遥无期
遥遥无期 2021-01-20 05:03
disc@puff:~/php$ ls 
a.php  data  include 

disc@puff:~/php$ tree 
. 
├── a.php 
├── data 
│   └── d.php 
└── include 
    ├── b.php 
    └── c.php 
2 directories, 4         


        
2条回答
  •  隐瞒了意图╮
    2021-01-20 05:41

    As you're starting with a.php, you should define the include directories in a.php:

    define('MY_INCLUDES', dirname(__FILE__) . '/include/');
    define('MY_DATA', dirname(__FILE__) . '/data/');
    

    Afterwards include the files with absolute paths:

    include(MY_INCLUDES . 'b.php');
    include(MY_DATA . 'c.php');
    

提交回复
热议问题