【发布时间】:2016-07-09 03:02:32
【问题描述】:
我正在尝试通过在页脚应该包含的 php 文件中包含 php 中的 include 语句。然而,我收到错误消息说
"include(includes/footer.php): failed to open stream: No such file or directory in "
或
“警告: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>
包含/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? -
试试 include(__DIR__ . '/includes/footer.php');
-
啊,fxing markdown。
-
那些
%20来自哪里?您的includes文件夹名称中有空格吗? -
我建议从文件夹名称中删除空格,而不是在代码中添加空格。不必每次都添加空间。