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 Enhancing a Simple PHP Application Cleaning URLs with Subfolders Server Paths and Constants

Grayson Swaim
Grayson Swaim
8,992 Points

PHP Include function is not working? Why?

On top of the html tag, before any of the html text, i typed:

<?php include('/../filename.php'); ?> <html> ... ... </htm>

Is there something wrong with this syntax?

5 Answers

Did you literally type in "filename.php" because the question is related to a file named "company.php"?

Task 2 asks you to use a relative path so you should not begin your path with a forward slash because that's a root-relative path.

A relative path to a file is the path to that file relative to the file you're currently at.

You're at this page: htdocs/about/leadership/index.php

and you need to include this file: htdocs/config/company.php

So from the index page, you would have to go up two levels to get to the htdocs folder which is your root folder. Then you could go down into the "config" folder which contains "company.php"

as i remember page is htdocs/leadership/config/company.php so you need /../../company.php because you need to go 2 folders up so ../ goes for each folder

Hi artemmuterko,

If you begin the path with a forward slash then it's a root-relative path. this path would be saying, start at the root and then go up to levels and you'll find "company.php" there.

For a root-relative path this should work "/config/company.php" but the instructions say to use a relative path and i'm not sure if it would check against that.

I just checked and that doesn't pass so either i'm wrong or it's checking to make sure you've used a relative path.

Grayson Swaim
Grayson Swaim
8,992 Points

Jason: You're right, the file name is related to "company.php."

So i figured it might look like... <?php include("../../config/company.php"); ?>

Is this right? If so, then why wouldn't it be passing?

That should be right. I just passed the challenge with this:

<?php include("../../config/company.php"); ?>

I can't see any difference. You have that as your first line? Try refreshing the page and starting over. It could be a little glitch.

Grayson Swaim
Grayson Swaim
8,992 Points

Artemmuterko, i tried /../../company.php, and it didn't pass fro some reason.

Grayson Swaim
Grayson Swaim
8,992 Points

It finally worked! thank you guys!