Reputation: 437
I'm trying to work with the include statement in php by including a php file where the footer is supposed to be. Yet, I am getting error messages saying
"include(includes/footer.php): failed to open stream: No such file or directory in "
OR
"Warning: include(): Failed opening 'includes/footer.php' for inclusion (include_path='.;C:\php\pear') " . I don't know if I am missing something or do I need to do something else when retrieving a file from a different folder? Here is code
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>
Upvotes: 4
Views: 2097
Reputation: 970
If your file structure is:
include.php
includes/
footer.php
you can use:
<?php include('./includes/footer.php'); ?>
if file structure is different, write relative or absolute path to target file. For example if file structure:
code/
include.php
includes/
footer.php
you can write:
<?php include('../includes/footer.php'); ?>
P.S. '../' is folder up, './' is current folder, '../../' is two folder up.
Good luck!
Upvotes: 1