我正在尝试使用php中的include语句,通过包含一个php文件作为页脚。但是,我收到了错误消息,指出“include(includes / footer.php):无法打开流:文件或目录不存在” 或者 “警告:include():无法打开'includes / footer.php'进行包含(include_path ='。; C:\ php \ pear')”。 我不知道是否遗漏了什么,或者当从不同文件夹检索文件时,我需要做其他事情吗?这是代码:
include.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/style.css"/>
<title>include</title>
<style type="text/css">
.foot-item{width:33.33% min-height:120px; border-right:solid 1px white; }
.foot-item:nth-last-child{ border-right:none;}
.foot-item h3 a{color:#0099ff; text-decoration:none;}
</style>
</head>
<body>
<div class="contain">
<article>
<header><h1>include</h1></header>
<section>
<blockquote>The include statement includes and evaluates the specified file. </blockquote>
<p>Default</p>
<div id="result">Result</div>
<?php
?>
</section>
</article>
<?php include('includes/footer.php');?>
</div>
</body>
</html>
includes/footer.php
<footer>
<div class="foot-item">
<h3><a href="#">Recent Posts</a></h3>
<ul><li>link<li><li>link<li><li>link<li></ul>
</div>
<div class="foot-item">
<h3><a href="#">Free Newsletters</a></h3>
<ul><li>link<li><li>link<li><li>link<li></ul>
</div>
<div class="foot-item">
<h3><a href="#">Social Links</a></h3>
<ul><li>link<li><li>link<li><li>link<li></ul>
</div>
</footer>
path/to/webroot/include.php
和path/to/webroot/includes/footer.php
? - user5051310include(__DIR__ . '/includes/footer.php');
应该可以解决问题。 - jpschroeder%20
是从哪里来的?你的includes
文件夹的名字里有空格吗? - user5051310