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 trialSteve Tanner
2,304 PointsError on inserting include file - looking for include_path?
Hi Everyone, I'm stumped here. I can't get mamp to show me the include file for the header in the shirts 4 mike exercise. The includes code is simple to insert but when I do I get this warning...
Warning: include(inc/header.php): failed to open stream: No such file or directory in - on line 1 Warning: include(): Failed opening 'inc/header.php' for inclusion (include_path='.:') in - on line 1
Is this reacting to my desktop server config? What does this mean?
Thanks!!!
Jose Soto
23,407 PointsIt doesn't look like your code came through. Please post your code again by wrapping it between 3 backticks as stated in the markdown cheatsheet. Thanks.
7 Answers
Steve Tanner
2,304 PointsHi Everyone, I found it. I opened the Webstart page on MAMP and clicked into PHP info, looked for Loaded Configuration File and saw the path: /Applications/MAMP/bin/php/php5.6.2/conf/php.ini
So, I figured out the path for my includes to be /Applications/MAMP/htdocs/inc/header.php
That did the trick. Thanks so much for your help!!!
Jose Soto
23,407 PointsAwesome! Great job on troubleshooting that.
simhub
26,544 Pointsthe error say's something like this "The files do not exist in the location you are referencing them." you should check your path or filename!
Steve Tanner
2,304 Points<?php include("inc/header.php"); ?>
and tried:
<?php include('inc/header.php'); ?>
This code looks correct to me. and header.php is inside inc but yet it appears that it can't been seen in Mamp due to a file path error? (My best guess)
Jose Soto
23,407 PointsAnd you do have the 'inc' directory? I'm guessing your directory structure looks something like this:
server_root/index.php
server_root/inc/header.php
If this is true and you're still getting that error message, I would check your MAMP php.ini file include_path directory.
If you're not sure where the php.ini file is located, create a phpinfo page and view it in your browser:
<?php phpinfo() ?>
Look for the value of Loaded Configuration File.
Once you know which php.ini file to look for, open it in a text editor and search for "include_path". Here is what an include path value normally looks like:
Unix
include_path=".:/php/includes"
Windows
include_path=".;c:\php\includes"
If you're still having trouble after this, I'd say try re-installing MAMP. I hope that helps.
Steve Tanner
2,304 PointsHi Jose, thanks for the pointers. I created the php info page and got a page full of data in return. Within, I located the "Loaded Configuration File" but alas, I don't fully understand (yet) what it is telling me. It looks like this:
Loaded Configuration File => (none) Scan this dir for additional .ini files => /Library/Server/Web/Config/php
Also, I have all my course files setup in the HTDOCS folder per the teachers instructions in the video.
My guess is I'm in need of the proper url path to the course include file?
Steve Tanner
2,304 PointsI also tried to find the include path with this bit of php:
''' print get_include_path();
'''
I got this in return:
.:
shawn stokes
5,651 Pointssounds like this include(inc/header.php);
is not pointing at the right directory structure for the file.
so in mamp you have a htdoc folder list every thing out that is in it. like you were typing out html it should help you find the right path.
<htdoc>
<includes>
<header.php>
</header.php>
</includes>
<index.php>
</index.php>
</htdoc>
now you can see that the path for include()
is "/includes/header.php" if your include folder is indented more or less then the index.php you will have to adjust you location accordingly.
failed to open stream: No such file or directory tell you what the problem is there is no such dir or file check were you file is. and your path to it /htdoc/treehouse/php/app/header.php or ../inc/header.php
Steve Tanner
2,304 PointsSteve Tanner
2,304 PointsThis is the code in question.... but it looks correct to me. Something else is going on?
<?php include("inc/header.php"); ?>
I also tried:
<?php include('inc/header.php'); ?>