1

我是 php 的初学者,试图制作一个 main.php 文件,其中包含页眉和页脚作为开始

头文件.php

<html>
<body>
<div class="header">
logo, navigation etc
</div>

页脚.php

<div class="footer">
Footer content here
</div>
</body>
</html>

和主文件

<?php include "header.php"; ?>
<div class="main content">
<h1> header </h1>
<p> paragraph </p>
</div>
<?php include "footer.php"; ?>

错误:

Warning: include(header.php): failed to open stream: No such file or directory in - on line 1
Warning: include(): Failed opening 'header.php' for inclusion (include_path='.:') in - on line 1

Warning: include(footer.php): failed to open stream: No such file or directory in - on line 6
Warning: include(): Failed opening 'footer.php' for inclusion (include_path='.:') in - on line 6

所有文件都在同一个文件夹中,并在 XAMPP 上进行

4

3 回答 3

1

您包含的任何文件都必须在您的include_path中。调用get_include_path以查看当前值。

于 2012-09-16T22:14:42.510 回答
0

如果页眉、页脚和主文件位于同一目录中,请尝试以下操作:

include dirname(__FILE__) . '/header.php';
于 2020-10-24T14:15:08.457 回答
0

您应该将文件添加到同一个文件夹中,以便它们位于同一个父目录中,然后您可以使用“include”直接访问它们例如:在名为 Home 的文件夹中,如果我创建第三个我可以使用的文件,则有 2 个 php 文件此代码“<?php 包括“找到的另外两个文件之一的名称。php”希望它清楚

于 2020-10-24T12:45:32.787 回答