【问题标题】:php cross files include paths confusionphp 交叉文件包含路径混淆
【发布时间】:2013-12-11 06:10:46
【问题描述】:

不同目录级别的两个文件同时调用同一个文件:

// 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] 解决方案,但它们都不起作用,因为它们都没有为像我这样的初学者提供详细的教学。

【问题讨论】:

  • 你使用的 dirname(FILE) 的详细信息是什么?
  • 到目前为止,我只被告知这样做:include(dirname(FILE).'../template/header.php');但不工作。我知道缺少某些东西,但我不知道是什么!

标签: php include document-root dirname


【解决方案1】:

试试这个..

require_once(__DIR__."/include/same_file.php");

include(__DIR__."/include/same_file.php");

【讨论】:

    猜你喜欢
    • 2013-12-17
    • 2018-08-25
    • 2013-03-21
    • 2012-03-25
    • 1970-01-01
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多