【问题标题】:header file include paths头文件包含路径
【发布时间】:2014-10-21 01:58:13
【问题描述】:

所有这些都包含在我的public_html 文件夹内的一个文件夹中。

/Public_Html
    /folder
        /css
            -style.css
        /includes
            -shop.css
            -header.php
            -footer.php
        /php
        /js
        /shop
            -index.php

        -index.php <-- homepage
        -config.php 

在我的 config.php 里面

define('ROOT_PATH',''http://example.net/folder');

我的 header.php 在顶部有这个

<?php include '../config.php';?>

问题是,我希望只在 header.php 中包含配置文件,但要让它的路径在它所在的任何目录中都可以工作。例如,它可以在 /shop 中正常工作,但不是根索引文件文件夹,因为 config.php 的路径不正确。

有什么建议吗?

【问题讨论】:

  • 1.如果您已经有 css 目录,则 shop.css 包含哪些内容? 2. 使用绝对路径而不是相对路径,问题解决了。
  • @Robert 因为它只包含在商店 index.php 中。因此它是一个包含,并且 css 路径写在每个页面中包含的 header.php 中。

标签: php html path include


【解决方案1】:

始终包括使用 realpath。

include realpath(__DIR__ . '/'. './config.php');

在config.php中这样包含文件

include realpath(__DIR__ . '/'. './includes/header.php');

如果不是 PHP5.3

include realpath(dirname(__FILE__) . '/'. './includes/header.php');

【讨论】:

  • 标头不包含在 config.php 中。 config.php 包含在标头中。
猜你喜欢
  • 2021-07-11
  • 1970-01-01
  • 2012-12-16
  • 1970-01-01
  • 1970-01-01
  • 2013-05-25
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
相关资源
最近更新 更多