所有这些都包含在我的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中,我有
定义(‘ROOT_PATH’,''http://example.net/folder');
我的header.php在顶部有这个
<?php include '../config.php';?>问题是,我希望只在header.php中包含配置文件,但使它的路径工作,无论它在什么目录下。因此,例如,它可以在/shop中正常工作,但不能在文件夹的根索引文件中工作,因为config.php的路径是不正确的。
有什么建议吗?
发布于 2014-08-27 21:07:32
始终包含使用realpath。
include realpath(__DIR__ . '/'. './config.php');在config.php中,以这种方式包含文件
include realpath(__DIR__ . '/'. './includes/header.php');如果不是PHP5.3
include realpath(dirname(__FILE__) . '/'. './includes/header.php');https://stackoverflow.com/questions/25527899
复制相似问题