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 trial

PHP Build a Simple PHP Application Creating the Menu and Footer Including the Header

Steve Tanner
Steve Tanner
2,304 Points

Error 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!!!

Steve Tanner
Steve Tanner
2,304 Points

This 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'); ?>

Jose Soto
Jose Soto
23,407 Points

It 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
Steve Tanner
2,304 Points

Hi 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
Jose Soto
23,407 Points

Awesome! Great job on troubleshooting that.

simhub
simhub
26,543 Points

the 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
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
Jose Soto
23,407 Points

And 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
Steve Tanner
2,304 Points

Hi 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
Steve Tanner
2,304 Points

I also tried to find the include path with this bit of php:

''' print get_include_path();

'''

I got this in return:

.:

sounds 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