来自不同目录级别的两个文件同时调用同一个文件:
// 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]
解决方案,但没有一个能够正常运行,因为它们都没有向像我这样的初学者提供详细的教学。
答案 0 :(得分:1)
试试这个..
require_once(__DIR__."/include/same_file.php");
或
include(__DIR__."/include/same_file.php");