来自不同目录级别的两个文件同时调用同一个文件:
// index.php
include('./include/same_file.php');
// Webpages/page1.php
include('../include/same_file.php');
// include/same_file.php
include('../template/header.php'); // failed to open on index.php
fopen('../files/text1.txt'); // failed to open on index.php
file('./files/AA.html'); // failed to open on /include/same_file.php
我已经尝试了几个小时来寻找解决方案并找到了dirname(__FILE__)
解决$_SERVER[DOCUMENT_ROOT]
方案,但它们都不起作用,因为它们都没有为像我这样的初学者提供详细的教学。