Php 如果我想包含另一个文件夹,如何获取链接路径

Php 如果我想包含另一个文件夹,如何获取链接路径,php,Php,我想知道我怎样才能给出另一个文件夹的include路径 例如,我有一个名为testfolder的项目。在测试文件夹中有一个文件夹,即assets文件夹和index.php文件。在“资源”文件夹中有两个文件夹,分别是“包含”和“xyz文件夹”。在include文件夹中有两个文件,分别是header.php和footer.php。在header.php文件中有三个链接home、product和customer。在xyz文件夹中有product.php和customer.php文件。 在index.

我想知道我怎样才能给出另一个文件夹的include路径

例如,我有一个名为testfolder的项目。在测试文件夹中有一个文件夹,即assets文件夹和index.php文件。在“资源”文件夹中有两个文件夹,分别是“包含”和“xyz文件夹”。在include文件夹中有两个文件,分别是header.php和footer.php。在header.php文件中有三个链接home、product和customer。在xyz文件夹中有product.php和customer.php文件。

在index.php、product.php和customer.php中,我想包括header.php和footer.php

但我不能选择正确的道路

<?php include('../../header.php');?>

<?php include('../../footer.php');?>

请帮助我,我如何给出正确的路径,如果我单击产品链接,那么header.php和footer.php将被加载。

尝试以下方法:

<?php
include_once(dirname(__FILE__) . '/database.class.php');
?>


参考:

如果您的目录看起来像这样:

src
->includes
  ->header.php
  ->footer.php
web
->index.php
如果要在index.php中包含页眉和页脚,请执行以下操作:

<?php
   //index.php
   include __DIR__.'/../src/includes/header.php';
   echo "foobar";
   include __DIR__.'/../src/includes/footer.php';
?>


基本上,我使用了下面的方法

<?php include_once('../include/header.php');?>
<?php include_once('../include/footer.php');?>

我想如果你能

 ../../header.php by ../include/header.php and

../../footer.php by ../include/footer.php.
然后你会得到准确的结果

 ../../header.php by ../include/header.php and

../../footer.php by ../include/footer.php.