Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPaul Braden
Courses Plus Student 6,734 PointsI keep getting this php error. Please help I can't seem to figure it out
Warning: include(inc/header.php): failed to open stream: No such file or directory in C:\xampp\htdocs\index.php on line 28
10 Answers
John Breiner
6,918 PointsThe inc folder is in the same folder as index? If index is in public and inc is on the same directory level as public, make sure to have ../inc/header.php
J.T. Gralka
20,126 PointsHey Paul Braden,
As Cole Jackowski pointed out, it might have something to do with the web server you're running on your local machine. Depending on how you have your server configured, you might need to use backslashes (\
) instead of forward slashes ('/') in your paths.
It's a pain in the rear, sometimes working between platforms, so it might help to check out the DIRECTORY_SEPARATOR
constant in the php documentation on Predefined Constants.
Best,
Coco Jackowski
12,914 PointsThis means that the file you tried to include()
wasn't found. Perhaps because you didn't put the filename string in quotes? Could depend on your system and configuration. Can you post a more full code snippet?
Paul Braden
Courses Plus Student 6,734 Pointsno they are in quotes
Coco Jackowski
12,914 PointsA quick look at http://www.php.net/manual/en/function.include.php shows include
used without parentheses, as in include 'file.php';
. Have you run it that way? Again, a code snippet might help.
Jason Anello
Courses Plus Student 94,610 PointsDo you have an 'inc' folder with 'header.php' in it?
Paul Braden
Courses Plus Student 6,734 Points<?php include("inc/header.php"); ?>
John Breiner
6,918 PointsIn other words its saying you aren't pointing directly to it.
Paul Braden
Courses Plus Student 6,734 PointsOk that was it but now I have two footers and two headers
John Breiner
6,918 PointsDo you have the include for the header and footer in there more than once? Do you have the code from the include file also in your index file as well? If not it shouldn't be happening.
Paul Braden
Courses Plus Student 6,734 PointsYeah all those things are good to go I don't get it.
John Breiner
6,918 PointsWithout seeing all of it, that's what I can think of. Try <?php include once(); ?> instead of just the include