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


Trevor Wood
Trevor Wood
17,828 Points

PHP relative path include, code challenge

The Challenge: There is a file located at htdocs/config/company.php on the server. We need to include that file to get access to some of information about the company. At the very top of the file below, before any of the HTML, include that company.php file using a relative server path.

My answer:

<?php include($_SERVER["DOCUMENT_ROOT"] . "/htdocs/config/company.php"); ?>

     <title>Leadership | Shirts 4 Mike</title>

    <p><strong>Owner:</strong> ????</p>
    <p><a href="/contact/">Contact</a></p>


The response: Bummer! It does not look like the config/company.php file is being included. Please try again.

I've also tried "company.php" "/company.php" "config/company.php" "/config/company.php" however none seem to work.

Can anybody help me with this code challenge?

4 Answers


The index.php is currently in the htdocs/about/leadership directory. The company.php file is located in htdocs/config/company.php , so you have to go back two folders before you can access the config folder.

Trevor Wood
Trevor Wood
17,828 Points

Thanks Harpreet, worked perfectly

I had the same problem, the "workdir" is not set correctly, using "include('../../workdir/config/company.php')" resolves the issue.

Abdulwahab Alansari
Abdulwahab Alansari
15,151 Points

Great, thanks, now I am able to pass the challenge. However, I am wondering where did "workdir" come from?

Kevin May
Kevin May
8,904 Points

I get so tired of these stupid challenges, taking way too much time and not getting anything out of them, I agree with Abdul that there is no mention of workdir anywhere, so I'm not sure how in the hell you're supposed to know this.

Andrew Breslin
Andrew Breslin
10,177 Points

Well, now that I've given up and looked up the answer, I can at least comfortably say "There is absolutely now way I could have gotten that one."

workdir? Where did that come from? It's nowhere in the code challenge.

Usually these challenges do a great job of forcing me to really try to understand what's going on and although it's frustrating at first, it usually eventually makes sense. I think whoever put this one together just made a mistake in wording the question.


Giacomo Alberini
Giacomo Alberini
9,548 Points

Hi guys!

I have to say that I am really surprised by the fact that this code does not work for me!

It was my first choice when I did this challenge but the answer is always the same: "Bummer! It does not look like the config/company.php file is being included. Please try again."

I even tried to use the $_SERVER['DOCUMENT_ROOT'] (with single and double quotes) to retrive the root of the document but I found that variable to be empty (I used var_dump() to discover its content).

No luck with require, require_once, include_once and Root-relative path.

In the preview the answer is always the same: "PHP Warning: include(../../config/company.php): failed to open stream: No such file or directory in /workdir/about/leadership/index.php on line 2 PHP Warning: include(): Failed opening '../../config/company.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /workdir/about/leadership/index.php on line 2"

It seeems that the PHP is not able to go backward to the right folder and it just searches for the file in the current directory (it's really weird, but I think it's looking for the file ../../config/company.php in the /about/leadership/ directory)

Can anybody help me? Is this an error of mine or is the system broken for some reason?

Thank you!


Giacomo Alberini
Giacomo Alberini
9,548 Points

This is the link to the Code Challenge which is the subject of this thread.

If you are able to find why it's not working, you'll be my next hero :)


Thank you!


There might be a problem with the code challenge.

The code in the "best answer" here should be the right code.

I found a recent thread with a similar problem: https://teamtreehouse.com/forum/problem-with-code-challenge-23

There's a workaround for it so that you can pass the challenge.

I will tag the staff in that new thread.